单击列表视图后,如何使用一个按钮执行多个活动?

时间:2018-06-29 07:27:54

标签: android image listview button onclicklistener

这是我的MainActivity,我想使用单个按钮,它将需要像类似于Listview的Multiple Button一样使用。请帮帮我。 After Clicking Image This Activity open in this i want to use a button

MainActivity.java

public class MainActivity extends AppCompatActivity {

List<DataItem> lstData;
Button button;
int pos = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    lstData = new ArrayList<>();

    lstData.add(new DataItem(R.drawable.image_1, "Katrina kaif", "34", "something"));
    lstData.add(new DataItem(R.drawable.image_2, "Deepika Padukone", "34", "something"));
    lstData.add(new DataItem(R.drawable.image_3, "Disha Patani", "34", "something"));
    lstData.add(new DataItem(R.drawable.image_4, "Tamanna Bhatia", "34", "something"));

    final ListView listView = (ListView) findViewById(R.id.listView);
    final CustomAdapter adapter = new CustomAdapter(MainActivity.this, R.layout.itemrow, lstData);
    listView.setItemsCanFocus(true);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent intent = new Intent();
            intent.putExtra("Actress", lstData.get(position).actressName);
            intent.putExtra("Image", lstData.get(position).resIdThumbnail);
            intent.putExtra("Age", lstData.get(position).actressAge);
            intent.putExtra("About", lstData.get(position).actressAbout);
            intent.setClass(MainActivity.this, Main2Activity.class);
            startActivity(intent);
        }
    });
}

}

此活动中有一个按钮,我需要该按钮才能触发另一个活动。

activity_main2.xml

请查看我发布的图片

Main2Activity.java

public class Main2Activity extends AppCompatActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    ImageView imageView = (ImageView)findViewById(R.id.imageView);
    CircleImageView circleImageView = (CircleImageView) findViewById(R.id.circleImageView);
    TextView textView = (TextView)findViewById(R.id.textView);
    TextView nameView = (TextView)findViewById(R.id.name_1);
    TextView ageView = (TextView)findViewById(R.id.age_1);
    TextView aboutView = (TextView)findViewById(R.id.about_1);
    Button button = (Button)findViewById(R.id.img_btn);

    textView.setText(getIntent().getStringExtra("Actress"));
    nameView.setText(getIntent().getStringExtra("Actress"));
    ageView.setText(getIntent().getStringExtra("Age"));
    aboutView.setText(getIntent().getStringExtra("About"));
    imageView.setImageResource(getIntent().getIntExtra("Image",R.drawable.image_1));
    circleImageView.setImageResource(getIntent().getIntExtra("Image",R.drawable.image_1));
    button.setText(getIntent().getIntExtra("Position",R.id.img_btn));
}

}

0 个答案:

没有答案