如何在点击列表视图的按钮时切换到另一个活动?

huangapple go评论153阅读模式
英文:

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

问题

我想要将两个不同的活动意图(FreeLine、MoveCircle)。

如果我点击开始按钮,它将始终启动 FreeLine。

如何在点击列表视图的按钮时切换到另一个活动?

如何区分这些意图..?

    @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) {
                // 如何分开这两个意图?
                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                mContext.startActivity(FreeLineIntent);
                Intent MoveCircleIntent = new Intent(v.getContext(), MoveCircle.class);
                mContext.startActivity(MoveCircleIntent);
            }
        });
        return convertView;
    }
英文:

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

if i click that start button it will always start 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;
}

答案1

得分: 0

Button btn = (Button)convertView.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // 如何分开这两个意图?
        String txtTitle = txt2.getText().toString();
        switch (txtTitle){
            case "你的文本的第一个标题":
                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                mContext.startActivity(FreeLineIntent);
                break;
            case "你的文本的第二个标题":
                Intent MoveCircleIntent = new Intent(v.getContext(), MoveCircle.class);
                mContext.startActivity(MoveCircleIntent);
                break;
        }
    }
});
英文:

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;
}
}
});

答案2

得分: 0

Button btn = (Button) convertView.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // 如何分开这两个意图??
        String txtTitle = txt2.getText().toString();
        switch (txtTitle) {
            case "你的文本的第一个标题":
                Intent FreeLineIntent = new Intent(v.getContext(), FreeLine.class);
                mContext.startActivity(FreeLineIntent);
                break;
            case "你的文本的第二个标题":
                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;
}
}
});***

huangapple
  • 本文由 发表于 2020年10月25日 20:36:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64523749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定