i have generated an code for calling an file and it works fine. now i have different names that exists in an file. i want to declare that in that file and when i enter that number i want to display that name alone in the output
the text file look like this
apple
------------
mango
-------------
pineapple
-------------
jackfruit
-------------
papaya
-------------
grapes
------------
gauva
-----------
i want to get selective output displaying only one word. can any one illustrate with an example for an file access?
and i want to declare apple [0], mango[1] and so on till gauva[6]
when i enter 6 it should display guava alone. can any one give some examples how to declare that for an file?
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Hellolistview extends ListActivity {
/** Called when the activity is first created. */
/* @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PlayWithRawFiles1();
}private void PlayWithRawFiles1() {
// TODO Auto-generated method stub
}
public void PlayWithRawFiles() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.drawable.my_base_data);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,str));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
}
});
buf.append(str + "\n" );
}
}
is.close();
// PlayWithSDFiles
// FilesDemo4
// onCreate
} }
if i change this statement it not showing the output . what problem is here ?
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Hellolistview extends ListActivity {
/** Called when the activity is first created. */
/* @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PlayWithRawFiles1();
}private void PlayWithRawFiles1() {
// TODO Auto-generated method stub
}
public void PlayWithRawFiles() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.drawable.my_base_data);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
// String str1 = str;
//String[] str1 = str;
String[] str1 = str.split("\\\n");
char[] ch = new char[500];
ch=str.toCharArray();
boolean flag1=true, flag2=true;
for(int i=0; i<ch.length; i++) {
switch(ch[i]) {
case ' ': flag1 = false;
break;
case '\n': flag1 = true;
continue;
}
if(flag1)
System.out.print(ch[i]);
}
int i = 0;
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,ch[i]));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text