Moving to a new activity when ListViewItem is clicked
Intent startMenuActivity = new Intent(c, Menu_Activity.class);
here c
is your context variable.
Explanation:
You are supposed to pass activity context as first argument.
Creating new activity when clicking on listView Item
First of all you can store the image drawable like
final int[] imageResources = new int[] {R.drawable.AKM, R.drawable.M416, R.drawable.UMP};
then you can pass the image resource id with the intent
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(Weaponry.this, WeaponDetails.class).putExtra("image", imageResources[position]));
}
});
Then in the WeaponDetails.class you can fetch the image resource and set the imageView using
int image = getIntent().getExtras().getInt("image");
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageResource(image);
start new activity on click listview item
Remove the onListItemClick()
from your CustomListView
class and place the startActivity()
method inside the convertView.setOnClickListener()
.
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), two.class));
}
});
How to start activity based on listview item click?
Try something like this
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(v.getContext(),ActivityYouWantToGo.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
v.getContext().startActivity(intent);
Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
}
});
EDIT
Just create this method on your BaseAdapter
public void StartActivityForImages(Context context, int i){
switch (i){
case 0:
Intent Intent = new Intent(context, Image0.class);
context.startActivity(Intent);
break;
case 1:
Intent Intent2 = new Intent(context, Image1.class);
context.startActivity(Intent2);
break;
case 2:
Intent Intent3 = new Intent(context, Image3.class);
context.startActivity(Intent3);
break;
......
}
}
And on your setOnClickListener()
You call this method as follows :
StartActivityForImages(v.getContext(),position);
Toast.makeText(context, "You Clicked " + result[position], Toast.LENGTH_LONG).show();
Efficient way to do it
If you don't want to create a method and do this stuff, you could do something like this :
Create a String with the name of your next class like :
String NextActivity = getPackageName()+".Image"+position;
And then you can do something like this :
try {
String className =getPackageName()+".Image"+2;
Intent openNewIntent = new Intent(v.getContext(), Class.forName( className ) );
startActivity( openNewIntent );
} catch (ClassNotFoundException e) {
Log.d("ERRORPEW", e.getMessage());
e.printStackTrace();
}
How to open new activity after clicking list view with search bar element?
You can search on a listview
and you can use OnItemClickListener
From search view
new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
mListView.clearTextFilter();
} else {
mListView.setFilterText(newText.toString()); //you can use this to filter items
}
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return true;
}
}
And in Listview
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//put some intent
}
}
For going to new Activity use this
Intent intent=new Intent(getBaseContext(),TargetActivity.class);
startActivity(intent);
refer
http://www.coderzheaven.com/2013/06/01/create-searchview-filter-mode-listview-android/
https://stackoverflow.com/a/5714068/5962715
listView onclick goes to a new activity
Use a switch statement in that method:
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch( position )
{
case 0: Intent newActivity = new Intent(this, superleague.class);
startActivity(newActivity);
break;
case 1: Intent newActivity = new Intent(this, youtube.class);
startActivity(newActivity);
break;
case 2: Intent newActivity = new Intent(this, olympiakos.class);
startActivity(newActivity);
break;
case 3: Intent newActivity = new Intent(this, karaiskaki.class);
startActivity(newActivity);
break;
case 4: Intent newActivity = new Intent(this, reservetickets.class);
startActivity(newActivity);
break;
}
}
Change the class names to whatever they need to be for each Activity.
Related Topics
Error Inflating Class Android.Support.V4.View.Viewpager
Mat (Eclipse Memory Analyzer) - How to View Bitmaps from Memory Dump
How Surfaceholder Callbacks Are Related to Activity Lifecycle
Turning on Wifi Using Wifimanager Stops to Work on Android 10
How to Put Recyclerview Inside Nestedscrollview
What Happens to Older Clients When You Migrate an App Server from Gcm to Fcm
Android Linearlayout Gradient Background
How to Paging Query from Firebase Using Android Firebaseui
How to Pin a Certificate with Square Okhttp
Android in Navigation Drawer When I Click Anywhere Drawer Closes
What Are The Default Color Values for The Holo Theme on Android 4.0
Picture Taken with Camera Intent Is Low Quality on Imageview (7.0+)
How to Create a Looper Thread, Then Send It a Message Immediately
Firebase Endat() Not Working with Date String
Android/iOS - Custom Uri/Protocol Handling
Emulator: Warning: Quick Boot/Snapshots Not Supported on This Machine