You must use ListView to display your posts.
Store the data received from the database in an array of strings, such as s1. Then
private ArrayList<String> arr_sort = new ArrayList<String>(); And copy all s1 to arr_sort using the add () method.
When setting up the adapter
lv.setAdapter(new ArrayAdapter<String>(DataAttach.this, android.R.layout.simple_list_item_1, arr_sort)); where lv is the ListView link.
Then use this method for onClick
lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String item = (String) lv.getItemAtPosition(position); Toast.makeText(*.this, "You selected - " + item + " ,Please wait...", Toast.LENGTH_LONG).show(); Intent intent = new Intent(*.this, *.class); *.this.startActivity(intent); } });
Hope this helps.
source share