简体   繁体   中英

How can i go to an other activity when i click button of list view?

I want to Intent two different activity(FreeLine, MoveCircle)

if i click that start button it will always start FreeLine

如果我单击那个开始按钮,它将始终启动 FreeLine

How to separate these intents..?

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final Context context = parent.getContext();

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(mLayout, parent, false);
        }

        ImageView img = (ImageView)convertView.findViewById(R.id.img);
        img.setImageResource(mDatas.get(position).Img);

        TextView txt = (TextView)convertView.findViewById(R.id.text);
        txt.setText(mDatas.get(position).Name);

        TextView txt2 = (TextView)convertView.findViewById(R.id.desc);
        txt2.setText(mDatas.get(position).Des);

        Button btn = (Button)convertView.findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //How to separate these two intents???
                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                mContext.startActivity(FreeLineIntent);
                Intent MoveCircleIntent = new Intent(v.getContext(), MoveCircle.class);
                mContext.startActivity(MoveCircleIntent);
            }
        });
        return convertView;
    }

You can do that by get the text:-

Button btn = (Button)convertView.findViewById(R.id.btn);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //How to separate these two intents???
                        String txtTitle = txt2.getText().toString();
                        switch (txtTitle){
                            case "the first title  of your text":
                                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                                mContext.startActivity(FreeLineIntent);
                                break;
                            case "the second title  of your text":
                                Intent MoveCircleIntent = new Intent(v.getContext(), MoveCircle.class);
                                mContext.startActivity(MoveCircleIntent);
                                break;
                                
                        }
                       
                      
                    }
                });
***Button btn = (Button)convertView.findViewById(R.id.btn);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //How to separate these two intents???
                        String txtTitle = txt2.getText().toString();
                        switch (txtTitle){
                            case "the first title  of your text":
                                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                                mContext.startActivity(FreeLineIntent);
                                break;
                            case "the second title  of your text":
                                Intent MoveCircleIntent = new Intent(v.getContext(), MoveCircle.class);
                                mContext.startActivity(MoveCircleIntent);
                                break;
                                
                        }
                       
                      
                    }
                });***

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM