2014年1月2日星期四

[Android] Click on an item in the ListView how to jump to another activity

For example, I wanted to write such a program
MobileHoll.java
package com.MobileHoll;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

public class MobileHoll extends Activity {
/ ** Called when the activity is first created. * /
String [] menues;
int [] pics;
ListView lv;
ImageView iv;

@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
ArrayAdapter mAdapter;
lv = (ListView) findViewById (R.id.ListView01);
iv = (ImageView) findViewById (R.id.ImageView01);
menues = new String [] {" prepaid balance inquiry ", " check points and redeem " , "package check " ; } ;
pics = new int [] {R.drawable.pic1, R.drawable.pic2, R.drawable.pic3};

mAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, menues);
lv.setAdapter (mAdapter);
iv.setImageResource (pics [0]);
lv.setOnItemClickListener (new OnItemClickListener () {

@ Override

public void onItemClick (AdapterView arg0, View arg1, ; int arg2, long arg3) {

}});
}
}
how to write in onItemClick so that when click on item " prepaid balance inquiry ", " check points and redeem " jump to the appropriate interface "package check " when ( I am a novice , seeking advice ) Thank
------ Solution --------------------------------------------
in public ; void onItemClick method written inside Intent to jump on the line chant ,
------ eference ------------------------ ---------------

I want to determine how to use arg2 click to the first of several project? Written like this a problem? ( Not always respond )
public void onItemClick (AdapterView arg0, View arg1, int arg2, long arg3) {
if (arg2 == 0) {
Intent intent = new Intent (MobileHoll.this , menue1.class);
startActivity (intent);
}
if (arg2 == 1) {
Intent intent = new Intent (MobileHoll.this , menue2.class);
startActivity (intent);
}
if (arg2 == 2) {
Intent intent = new Intent (MobileHoll.this , menue3.class);
startActivity (intent);
}
------ eference ----------- ----------------------------
your landlord does not mean the end point of the reaction , or do what
you
public void onItemClick (AdapterView arg0, View arg1, int arg2, long arg3) {
Log.v ("aaa", arg2 + "");
}
Then you click, look at what can be displayed .
------ eference --------------------------------------- < br>
turned out I forgot to add the activity in the manifest inside the · · · but thank you, hey

没有评论:

发表评论