Answer the question
In order to leave comments, you need to log in
How to pass post id from ListView to another Activity?
There is a ListView in which a brief description of the posts is loaded via REST. When you click on a list item, a second activity is called, which requests extended data on the publication from the server and displays it to the user.
I figured out the transfer of the post_id parameter itself. In the ListView, I hung a handler on the list items:
lv_posts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Main.this, PostDetails.class);
intent.putExtra("post_id", "61509");
startActivity(intent);
}
});
Intent intent = getIntent();
post_id = intent.getStringExtra("post_id");
Answer the question
In order to leave comments, you need to log in
Use RecyclerView (you implement it inside the ViewHolder and put an identifier when binding the view), identifiers can be implemented both in the Model class and through .setTag("your_tag");
Usually they create a special class, they call it ViewHolder, which then, using setTag(), you can save your ViewHolder instance in a specific ListViewItem, with the corresponding data, you can get it from item using getTag(), casting it to the desired ViewHolder class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question