I can't start a new activity clicking over an item in my listview. I want that onItemClick
can open the ApkInfoActivity
.. Actually when i click nothing happen.
protected void onItemClick(ListView l, View v, int position, long id, AdapterView<?> parent) {
super.onListItemClick(l, v, position, id);
final ApplicationInfo app = applist.get(position);
PackageInfo packageInfo = (PackageInfo) parent.getItemAtPosition(position);
AppDataActivity appData = (AppDataActivity) getApplicationContext();
appData.setPackageInfo(packageInfo);
Intent appInfo = new Intent(getApplicationContext(), ApkInfoActivity.class);
startActivity(appInfo);
}
I can't find the problem..How can i solve?
EDIT with logcat:
10-29 17:14:07.710: E/AndroidRuntime(3535): FATAL EXCEPTION: main
10-29 17:14:07.710: E/AndroidRuntime(3535): java.lang.ClassCastException: android.content.pm.ApplicationInfo cannot be cast to android.content.pm.PackageInfo
10-29 17:14:07.710: E/AndroidRuntime(3535): at com.dd.application.MainActivity.onItemClick(MainActivity.java:369)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.widget.AdapterView.performItemClick(AdapterView.java:297)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.widget.AbsListView.performItemClick(AbsListView.java:1149)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2939)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.widget.AbsListView$2.run(AbsListView.java:3622)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.os.Handler.handleCallback(Handler.java:730)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.os.Handler.dispatchMessage(Handler.java:92)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.os.Looper.loop(Looper.java:137)
10-29 17:14:07.710: E/AndroidRuntime(3535): at android.app.ActivityThread.main(ActivityThread.java:5323)
10-29 17:14:07.710: E/AndroidRuntime(3535): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 17:14:07.710: E/AndroidRuntime(3535): at java.lang.reflect.Method.invoke(Method.java:525)
10-29 17:14:07.710: E/AndroidRuntime(3535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:743)
10-29 17:14:07.710: E/AndroidRuntime(3535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
10-29 17:14:07.710: E/AndroidRuntime(3535): at dalvik.system.NativeStart.main(Native Method)
How can you react to click events on an item of a ListView? Place an empty linearlayout below the listview by setting an appropriate height to the listview. Place an onClick() method to that linear layout. That must do it.
Find the array for the field you want to display as a link (e.g. custom_link_c ). Add 'type'=>'name', and 'link'=>true, to the array for the field, which will override the stock field's vardef and make the field clickable.
This example demonstrates how do I dynamically update a ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
An API is used to get selected items from the list items. This is called as the getSelectedItems method.
Use This for doing your work
list.setOnItemClickListener(new AdapterView.onItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
Intent appInfo = new Intent(YourActivity.this, ApkInfoActivity.class);
startActivity(appInfo);
}
});
public class MenuYangu extends ListActivity {
String classes[] = { "Quiz Trivia", "Sign A New User", "Friend List",
"Download A File", "Upload A File", "Select Pdf files", "Memory Game",
"Dzidza Maths", "Write Exam" };
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menuone.this,
android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
if (position == 0) {
Intent intent = new Intent(this, QuizActivity.class);
startActivity(intent);
}
else if (position == 1) {
Intent intent = new Intent(this, SignUp.class);
startActivity(intent);
}
else if (position == 2) {
Intent intent = new Intent(this, FriendList.class);
startActivity(intent);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With