I have created listview in Android to show my records. And records are shown as well. Now I want to click on particular record from that listview to show/view particular record. And that record must show another layout for that profile. How to achieve it?
Create a onItemClick() event for the listview. Then, when you click on an item, a new intent will be created that will start a child activity that will display the particular record.
listView1.setOnItemClickListener(new ListView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> listView, View itemView, int itemPosition, long itemId)
{
Intent launchActivity = new Intent(MyActivity.this, OtherActivity.class);
startActivity(launchActivity);
}
});
Related
I have a ListView being populated via a SimpleCursorAdapter. The row uses a FrameLayout to allow the user to tap on the left or right side of the row, which will trigger two different activities. I have the tap working and they go to the appropriate activities, but I am stuck on figuring out how to make the resulting views show the data related to the row tapped on.
The code used to go to the new activities are:
public void goToCaptureBonus (View View) {
Log.e(TAG,"goToCaptureBonus");
Intent goToCaptureBonus = new Intent(this,captureBonus.class);
startActivity(goToCaptureBonus);
}
public void goToBonusDetail (View View) {
Log.e(TAG,"goToBonusDetail");
Intent goToBonusDetail = new Intent(this,bonusDetail.class);
startActivity(goToBonusDetail);
}
I am currently using the following in my onCreate, but I think this is trying to read the entire list view, not just the two frames I made in my row.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent nextActivity = new Intent(bonusListing.this, bonusListing.class);
startActivity(nextActivity);
}
});
I want to have the app pass the row data to the goToCaptureBonus and goToBonusDetail activities when their associated frames are tapped, so that those activities will know what data to read from my DB.
I have 2 activity in my app.
From First activity I take data to second activity's listview. In second activity I have a listview to show datas. Normally when I create a list and values myself I can create click event but now datas coming from other activity, and the datas uncertain.. How can I create click event for coming datas?(sorry for my very bad grammar)
It's my first activity;
Intent veri = new Intent(elementler.this,sonuclar.class);
veri.putStringArrayListExtra("logoveri", clickeddata);
startActivity(veri);
//I sent data for second activity's list
It's my list class;
//fetch values
Intent veri = getIntent();
veriler = veri.getStringArrayListExtra("logoveri");
//there are a lot of possibility in "veriler" maybe user select banana maybe apple maybe car maybe computer we can not know what he select..
//create a list with fetch data
ListView sonuclistesi=(ListView) findViewById(R.id.sonuclistesi);
ArrayAdapter<String> veriadaptoru=new Listeozellikleri(this,veriler);
sonuclistesi.setAdapter(veriadaptoru);
You can give listView onitem click,
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// do your stuff
}
});
I want to get all the items in a list view that way when each one is clicked they will open the second activity?
Here I can get a specific list view item and use an if statement to say if this is clicked open/launch the second activity but I want to be able to say if any list view item is clicked open/launch the second activity how do I do that I know it sounds simple??
public void onItemClick(AdapterView<?> listView, View itemView, int itemPosition, long itemId)
{
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
});
when I remove the if statement it keeps crashing logcat states:"RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list" am using :android:id="#android:id/list" my activity also extends ListActivity? I dont't get it
If I understand your question:
but I want to be able to say if any list view item is clicked open/launch the second activity how do I do that I know it sounds simple??
Just remove the if block like this:
public void onItemClick(AdapterView<?> listView, View itemView, int itemPosition, long itemId)
{
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
}
});
And your second activity will be opened on any item click.
Hope this helps...
I have an Android GridView inside an ExpandableListView. All data is appearing fine but I can not find a way to handle GridView Item Click event. I just want to open up another Intent upon clicking on a grid's cell and pass a value to the intent.
Is it possible?
Thanks.
YourGrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent = new Intent(this,
MyNewActivity.class);
startActivity(intent);
}
});
Make sure in your GridLayout there is no clickable content like buttons otherwise they'll fired instead of this
grid.setOnChildClickListener();
may solve your problem!
For example i have a video gallery. I scroll to a certain video click on it and a whole new activity starts. Whats the most efficient way to code this?
If you have a list, I'm sure you are getting a hold of it in the code and assigning an Adapter. You can define what happens (starting an activity) by defining setOnItemClickListener() as such:
final ListView list = (ListView)findViewById(R.id.myVideoList);
MyVideoAdapter adapter = new MyVideAdapter(this);
list.setAdapter(adapter);
list.setOnItemClickListener(new ListView.OnItemClickListener(){
public void onItemClick(AdapterView<?> av, View v, int position, long id){
MyVideoObject video = (MyVideoObject)av.getItemAtPosition(position);
Intent intent = new Intent(CurrentActivity.this, SelectedVideo.class);
intent.putExtra("video_id, video.getID());
startActivity(intent);
}
});
All you're doing above is to initializing the list and assigning what happens when the user clicks on the list item.
When a click happens, you're getting a hold of the video item (however you're juggling them between activities) and passing perhaps its ID to the new Activity you wanna launch. The new activity (SelectedVideo.class) can receive the ID in onCreate and perhaps play the video.
Hope this helps,
-serkan