在列表视图的项目点击它将开始新的活动

时间:2013-07-26 10:13:19

标签: android listview

所有 我是android的新手,我对这个简单的解决方案搞砸了, 你能帮我么。 在项目上单击任何列表项,它将启动新活动? 它没有前进。 这段代码有什么问题?

public class AddBiller extends Activity {
ListView billerlistview;
String[] loclist = { "Mumbai", "Pune", "Bangalore", "Hydrabad" };
Button backbtn;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addbiller);
    billerlistview = (ListView) findViewById(R.id.billerlist);
    initViews();

}

private void initViews() {

    billerlistview.setAdapter(new AddBilleradapter(this, loclist));
    billerlistview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            Intent detailIntent = new Intent(AddBiller.this,
                    CatergoryActivity.class);
            //detailIntent.putExtra("biller", 0);
            startActivity(detailIntent);

        }

    });
}

public void onItemSelection(String string) {
    Intent detailIntent = new Intent(AddBiller.this,
            CatergoryActivity.class);

    startActivity(detailIntent);

}

}

public class AddBilleradapter extends ArrayAdapter<String>{
AddBiller context;
 String[] items;
public AddBilleradapter(AddBiller addbillercontext, String[] items) {
    super(addbillercontext,R.layout.addbiller,items);
    context = addbillercontext;
    this.items = items; 
}
 public View getView(final int position, View convertView, ViewGroup parent) {

     //  View row = convertView;
       if (convertView == null) {
               LayoutInflater inflater = (LayoutInflater) context
                               .getLayoutInflater();
               convertView = inflater.inflate(R.layout.menuitem, null);

       }
       TextView text = (TextView) convertView.findViewById(R.id.name);
       text.setTextColor(Color.BLUE);
       text.setText(items[position]);
     /*  convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {



            }
        });*/

       return convertView;

}

}

0 个答案:

没有答案