填充来自多个编辑文本数据的自定义列表视图 [英] Populating Custom List View with data from multiple Edit Texts

查看:252
本文介绍了填充来自多个编辑文本数据的自定义列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是我做了一个表格3 EditTexts和两个按钮,确定和取消

So I made a form with 3 EditTexts and two Buttons, "Ok" and "Cancel"

下面是我的code吧:

Here's my Code for it:

package com.examples.edtTxtCustomList;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class InputPage extends Activity implements OnClickListener{

    private Button btnGo,btnCancel;
    EditText et_name,et_email,et_phone;

    List<String> data = new ArrayList<String>();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_list_view);


        et_name = (EditText) findViewById(R.id.et_name);
        et_email =(EditText)findViewById(R.id.et_email);
        et_phone = (EditText)findViewById(R.id.et_phno);
        btnGo = (Button) findViewById(R.id.btn_ok);

        btnGo.setOnClickListener(this);
        data.add("Welcome");

    }

        @Override
        public void onClick(View src) {

            String nm=et_name.getText().toString();
            String no = et_email.getText().toString();
            String mail= et_phone.getText().toString();

            Intent i = new Intent(this,CustomLayout.class);

            i.putExtra("name", nm);
            i.putExtra("email", mail);
            i.putExtra("phone", no);
            startActivity(i);

        }    
}   `

这是我的形式的XML文件:

And here's the XML file of my form:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/tv_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="20dip"
            android:layout_marginBottom="10dip"
            android:text="Name :"
            android:textSize="20dip"/>

        <EditText 
            android:id="@+id/et_name"
            android:layout_width="230dip"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/tv_name"
            android:layout_alignTop="@id/tv_name"
            android:layout_marginBottom="10dip"
            android:layout_marginLeft="8dip"
            android:textSize="15dip"/>

        <TextView
            android:id="@+id/tv_email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="20dip"
            android:layout_marginBottom="10dip"
            android:layout_below="@id/tv_name"
            android:text="E-Mail :"
            android:textSize="20dip"/>

        <EditText 
            android:id="@+id/et_email"
            android:layout_width="230dip"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/tv_email"
            android:layout_alignTop="@id/tv_email"
            android:layout_below="@id/et_name"
            android:inputType="textEmailAddress"
            android:layout_marginLeft="6dip"
            android:layout_marginBottom="10dip"
            android:textSize="15dip"/>

        <TextView
            android:id="@+id/tv_phno"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="20dip"
            android:layout_marginBottom="10dip"
            android:layout_below="@id/tv_email"
            android:text="Phone :"
            android:textSize="20dip"/>

        <EditText 
            android:id="@+id/et_phno"
            android:layout_width="230dip"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/tv_phno"
            android:layout_alignTop="@id/tv_phno"
            android:layout_below="@id/et_email"
            android:inputType="phone"
            android:layout_marginLeft="5dip"
            android:layout_marginBottom="10dip"
            android:textSize="15dip"/>

        <Button 
            android:id="@+id/btn_ok"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/et_phno"
            android:layout_marginTop="30dip"
            android:layout_marginLeft="50dip"
            android:text="OK"
            android:textSize="20dip"/>

        <Button 
            android:id="@+id/btn_cancel"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/et_phno"
            android:layout_marginTop="30dip"
            android:layout_marginRight="50dip"
            android:text="Cancel"
            android:textSize="20dip"/>      
    </RelativeLayout>
</LinearLayout>

现在我想的是,当我在OK,从三个编辑文本的所有数据单击应显示在customlistview。

now what I want is,when i click on "OK" all the data from all three of the edit texts should be displayed in the customlistview.

我试图让一个动态列表视图如下:

I tried to make a dynamic listview as follows:

package com.example.customlist;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;


public class CustomListLayoutActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_list_view);

        SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.custom_row_layout,
                new String[] {"Name","Email","Phone"},
                new int[] {R.id.text1,R.id.text2, R.id.text3}
                );
        populateList();
        setListAdapter(adapter);
    }

    static final ArrayList<HashMap<String,String>> list = 
        new ArrayList<HashMap<String,String>>(); 

    private void populateList() {
        HashMap<String,String> temp = new HashMap<String,String>();
        temp.put("Name","Anurag Kulkarni");
        temp.put("Email", "kulkarni_anurag@yahoo.com");
        temp.put("Phone", "+91-9904475805");
        list.add(temp);
        HashMap<String,String> temp1 = new HashMap<String,String>();
        temp1.put("Name","Rahul Shah");
        temp1.put("Email", "rahul201290@gmail.com");
        temp1.put("Phone", "+91-9898434909");
        list.add(temp1);
        HashMap<String,String> temp2 = new HashMap<String,String>();
        temp2.put("Name","Pratik Thakkar");
        temp2.put("Email", "iamcool@cooldood.com");
        temp2.put("Phone", "+91-8539524925");
        list.add(temp2);
        HashMap<String,String> temp3 = new HashMap<String,String>();
        temp3.put("Name","Utsav Patel");
        temp3.put("Email", "patel_in_a_hotel@dhokla.com");
        temp3.put("Phone","+91-9843500999");
        list.add(temp3);
        HashMap<String,String> temp4 = new HashMap<String,String>();
        temp4.put("Name","Karan Mohan");
        temp4.put("Email", "masala_dosa@sankalp.co.in");
        temp4.put("Phone", "+91-9944843974");
        list.add(temp4);

    }
}

你能帮帮我吗?我仍然在学习的基础,所以任何帮助将appriciated。

Can you please help me with it? I am still learning the basics,so any help would be appriciated.

感谢。

推荐答案

正如我的另一篇文章...

As in another post of mine...

当你想要做的处理,在一个ListView的意见你
  需要创建一个自定义适配器,将处理你的逻辑
  实施和传递信息的意见是必要的。

Whenever you want to do processing with the views in a ListView you need to create a custom adapter that will handle your logic implementation and pass that information to the views as necessary.

自定义adater会膨胀一块的看法一块,这可能是
  动态固定的。

A custom adater would inflate the views piece by piece, this can be dynamic of fixed.

例如:

<一个href=\"http://android.vexedlogic.com/2011/04/02/android-lists-listactivity-and-listview-ii-%E2%80%93-custom-adapter-and-list-item-view/%20%22Link%201%3a\"相对=nofollow>链接1

这篇关于填充来自多个编辑文本数据的自定义列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆