Vote count:
0
I'm creating an app which is showing some text files in listview using ArrayList. now, I want to open the file which is clicked by the user in another layout or else. I want like "OnItemClickListener", but I get the error: The method setOnItemClickListener(AdapterView.OnItemClickListener) in the type AdapterView is not applicable for the arguments (new OnItemClickListener(){})
Please help me in doing so. My code is:
public class AllNotes extends Activity {
Button button;
TextView textview;
private ListView mainListView ;
private ArrayAdapter<String> listAdapter ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_notes);
String path = Environment.getExternalStorageDirectory().toString()+ "/" + FirstOneAct.foldername;
Log.d("Files", "Path: " + path);
File f = new File(path);
File file[] = f.listFiles();
Log.d("Files", "" + file.length);
Toast.makeText(this, "" + file.length ,Toast.LENGTH_SHORT).show();
for (int i=0; i < file.length; i++)
{
mainListView = (ListView) findViewById( R.id.mainListView );
ArrayList<String> planetList = new ArrayList<String>();
// Create ArrayAdapter using the planet list.
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList);
for (int j=0; j < file.length; j++)
{
listAdapter.add(file[j].getName());
}
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter( listAdapter );
Log.d("Files", "FileName:" + file[i].getName());
Toast.makeText(getApplicationContext(), file[i].getName(),Toast.LENGTH_LONG).show();
}
mainListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.d("############","Items " + MoreItems[arg2] );
}
});
}
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire