KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am getting an error when trying to set my view to display the ListView for the file I want to display(text file). I am pretty sure it has something to do with the XML. I just want to display the information from this.file = fileop.ReadFileAsList("Installed_packages.txt"); . My code: public class Main extends Activity { private TextView tv; private FileOperations fileop; private String[] file; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.fileop = new FileOperations(); this.file = fileop.ReadFileAsList("Installed_packages.txt"); setContentView(R.layout.main); tv = (TextView) findViewById(R.id.TextView01); ListView lv = new ListView(this); lv.setTextFilterEnabled(true); lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, this.file)); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); setContentView(lv); } } list_item.xml : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp" android:textSize="16sp" android:textColor="#000"> </LinearLayou
Tags (comma-separated)
Save Edits
Cancel