I am pretty new to android programming, hence can't solve many things on my own. For last few hours, I was trying to write code for doing some activity based on user click on a list view. Basically, I need to do below:
1) I already have successfully generated a listview with BOOK ID, BOOK NAME and WRITER information 2) If I click on each row, I want to read the BOOK ID of that row, go back to Main Page and then run a predefined function x(BOOK_ID) on main page.
I tried to search a lot, but being a novice, everything is just making me more confused. Any help will be much appreciated.
Single Block for Listview:
<TextView
android:id="@+id/bookname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book Title" />
<TextView
android:id="@+id/bookid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book ID" />
<TextView
android:id="@+id/writer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Writer" />
</RelativeLayout>
Java Class:
mylibmandbhandler db = new mylibmandbhandler(this);
List<mylibman> allfld = db.getAllRecord();
ArrayList<HashMap<String, String>> allbookList = new ArrayList<HashMap<String, String>>();
for (mylibman cn : allfld) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(LIST_KEY_ID, Integer.toString(cn.getBookid()));
map.put(LIST_KEY_NAME, cn.getBookname());
map.put(LIST_KEY_WRITER, cn.getWriter());
allbookList.add(map);
}
list=(ListView)findViewById(R.id.list);
adapter=new MylibmanList(this, allbookList); //calling adapter class
list.setAdapter(adapter);
// UPTO THIS POINT CODE IS WORKING FINE
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// NEED TO GET THE BOOKID OF THE ROW UPON CLICKING, GO BACK TO MAIN ACTIVITY, AND CALL A FUNCTION X()
}
});