I have an activity with a ListView in that ListView I had written a certain question. Now I just want that by clicking on each question respectively it will retrieve some selected data from the text file that I had created and shown that answer to some other activity.
Anyone please help me and provide me the code.
public class MainActivity4 extends AppCompatActivity implements AdapterView.OnItemClickListener {
String[] name={"Tell me about yourself ?"
,"Describe yourself in one word ?",
"Why did you leave your last job ?",
"What is your strength"};
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity4_main);
lv=(ListView)findViewById(R.id.listView);
ArrayAdapter adapter =new ArrayAdapter(this,android.R.layout.simple_list_item_1,name);
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), parent.getItemAtPosition(position)+"", Toast.LENGTH_LONG).show();
}
}