Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android listview 如何发送ArrayList的值<;HashMap<;字符串,对象>&燃气轮机;从一项活动到另一项活动_Android Listview_Arraylist_Hashmap - Fatal编程技术网

Android listview 如何发送ArrayList的值<;HashMap<;字符串,对象>&燃气轮机;从一项活动到另一项活动

Android listview 如何发送ArrayList的值<;HashMap<;字符串,对象>&燃气轮机;从一项活动到另一项活动,android-listview,arraylist,hashmap,Android Listview,Arraylist,Hashmap,这是ListView <LinearLayout … > <ListView android:id="@+id/listView1" > </ListView> </LinearLayout> 我的新活动中只需要“hm.put(Form3,3”);(正确地说只有“3”值)。 帮我把它正确地组成。你有什么问题?不清楚,只是我认为您在Spisok活动中有一个按钮。因此,您需要在noCreate()方法中创建一个按

这是ListView

<LinearLayout
   … >
    <ListView
        android:id="@+id/listView1" >
    </ListView>
</LinearLayout>
我的新活动中只需要“hm.put(Form3,3”);(正确地说只有“3”值)。
帮我把它正确地组成。

你有什么问题?不清楚,只是我认为您在Spisok活动中有一个按钮。因此,您需要在
noCreate()
方法中创建一个
按钮
对象,如下所示

Button button1 = (Button)findViewById(R.id.button1);
   button1.setOnClickListener(new onClickListener() {
     @Override
     public void onClick (){
     Intent intent = new Intent (this, SecondActivity.class );
     startActivity(intent);
   }
}

SecondActivity.class
是您的新活动。您需要使用IDE手动创建此活动类,还需要在
Manefist
文件中添加此活动。您可以将
TextView text3
SecondActivity的布局文件放入。

您必须使用该方法将R.id.text3的文本放入您的意图中

您的
监听器可以如下所示:

listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<> arg0, View arg1, int position,
        long arg3) {
    Intent intent = new Intent (this, SecondActivity.class );
    intent.putExtra("key for my item 3", "put the text you want to transfer here")
    startActivity(intent);

}
});
@Override
public void onCreate(Bundle savedInstanceState){
    Intent intent = getIntent();
    String transferedText = intent.getStringExtra("key for my item 3");
}

您有一个自定义的ListView(没有ListView,您无法在一行中管理更多的项目),每行有两个文本视图和一个按钮。如果用户单击按钮,则需要打开显示第二个文本视图的新活动

在适配器类的getView()方法中编写以下代码

   @Override
public View getView(final int position, View convertView, ViewGroup parent)
{ 
View row = convertView;
Button button1 = (Button) convertView.findViewById(R.id.button1);
TextView text1 = (TextView)convertView.findViewById(R.id.textview1);
TextView text2 = (TextView)convertView.findViewById(R.id.textview2);

button1.setOnClickListener(new OnClickListener()
{
 deleteButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              Intent intent = new Intent (this, SecondActivity.class );
              String text = text2.getText().toString();
               intent.putExtra("name", "text");                   
              startActivity(intent);  
            }
        });

}
然后编写这个代码

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.intent);
    Textv = (TextView)findViewById(R.id.tv2);
    Intent iin= getIntent();
    Bundle b = iin.getExtras();

    if(b!=null)
    {
        String j =(String) b.get("name");
        Textv.setText(j);
    }
}

希望这能帮助你

你有什么问题?将数据从一个
活动
传输到另一个活动?或者创建一个新的
活动
?“将数据从一个活动传输到另一个活动”是个问题。根据botton在cell的说法,新的活动必须有“text3”字样。“出了问题”太含糊了。你必须描述你的问题或显示你的错误。以下是如何询问的说明:。没有错误。只是这是错误的:intent.putExtra(“form3”,form3);如何更正输入/获取值?是的,但根据我的回答,我应该如何根据单元格中按下的按钮执行由“text3”组成的新活动。现在,如果按下按钮1,则打开第二个活动。第二个活动已经有了一个文本视图(text3)。现在,当用户按下按钮1时,是否要在文本3中显示任何信息??请清除它:text 1 text 2 botton1/text(1)3 text(2)4 botton1(2)/text(1)5 text(2)6 botton(1)3/如果我按botton1应该用“text 2”打开新活动,如果我按botton(1)3->打开“text(2)6”,请不要将代码放入注释中!用评论更新您的问题。抱歉,我正忙于其他任务。
listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<> arg0, View arg1, int position,
        long arg3) {
    Intent intent = new Intent (this, SecondActivity.class );
    intent.putExtra("key for my item 3", "put the text you want to transfer here")
    startActivity(intent);

}
});
@Override
public void onCreate(Bundle savedInstanceState){
    Intent intent = getIntent();
    String transferedText = intent.getStringExtra("key for my item 3");
}
   @Override
public View getView(final int position, View convertView, ViewGroup parent)
{ 
View row = convertView;
Button button1 = (Button) convertView.findViewById(R.id.button1);
TextView text1 = (TextView)convertView.findViewById(R.id.textview1);
TextView text2 = (TextView)convertView.findViewById(R.id.textview2);

button1.setOnClickListener(new OnClickListener()
{
 deleteButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              Intent intent = new Intent (this, SecondActivity.class );
              String text = text2.getText().toString();
               intent.putExtra("name", "text");                   
              startActivity(intent);  
            }
        });

}
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.intent);
    Textv = (TextView)findViewById(R.id.tv2);
    Intent iin= getIntent();
    Bundle b = iin.getExtras();

    if(b!=null)
    {
        String j =(String) b.get("name");
        Textv.setText(j);
    }
}