I've got a ListView which populates a list of quotes from a String Array, however onClick I require the selected <item> to be read to a String. This is the code I use:
ListView sample = (ListView)findViewById(R.id.Samplelist);
String[] backup = getResources().getStringArray(R.array.months);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, backup);
sample.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
final String item = (String) parent.getItemAtPosition(position);
view.animate().setDuration(2000).alpha(0)
.withEndAction(new Runnable() {
@Override
public final void run()
{
String readItem;
finish();
}
});
}
sample.setAdapter(adapter);
}
And here sample.setAdapter(adapter) seems to be an error and is underlined with red.
Is there a way to get this done correct? Any help will be appreciated
onClickmethod code