首页 > 代码库 > android基础 sqlite listview activity返回值

android基础 sqlite listview activity返回值

android基础  sqlite listview activity返回值

[1].[代码] [Java]代码 跳至 [1] [2]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
packagecom.it.db;
 
importjava.util.List;
importcom.it.dao.PersonDao;
importcom.it.domain.Person;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.BaseAdapter;
importandroid.widget.ListView;
importandroid.widget.TextView;
 
publicclass MainActivity extendsActivity {
    privateListView lv;
    privateList<Person> persons;
    @Override
    protectedvoid onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         
        PersonDao dao=newPersonDao(this);
        persons=dao.findAll();
        lv=(ListView) findViewById(R.id.lv);
        lv.setAdapter(newMyAdapter());
         
        lv.setOnItemClickListener(newOnItemClickListener() {
            //点击的数据 传到上一个activity
            @Override
            publicvoid onItemClick(AdapterView<?> parent, View view,
                    intposition, longid) {
                // TODO Auto-generated method stub
                Person mperson=persons.get(position);
                String number=mperson.getNumber();
                Intent data=http://www.mamicode.com/newIntent();
                data.putExtra("number", number);
                setResult(0, data);
                //点击 即关闭此activity
                finish();
            }
        });
    }
     
    privateclass MyAdapter extendsBaseAdapter{
        privatestatic final String TAG = "MyAdapter";
 
        /**
         * 控制listview里有多少个条目
         */
        @Override
        publicint getCount() {
            // TODO Auto-generated method stub
            returnpersons.size();
        }
 
        @Override
        publicObject getItem(intposition) {
            // TODO Auto-generated method stub
            returnnull;
        }
 
        @Override
        publiclong getItemId(intposition) {
            // TODO Auto-generated method stub
            return0;
        }
 
        @Override
        publicView getView(intposition, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            /**
             * 采用inflater显示
             */
            Person person=persons.get(position);
            View view=View.inflate(MainActivity.this, R.layout.list_item, null);
             
            TextView tv_id=(TextView) view.findViewById(R.id.tv_id);
            tv_id.setText("id:"+person.getId());
             
            TextView tv_name=(TextView) view.findViewById(R.id.tv_name);
            tv_name.setText("姓名:"+person.getName());
             
            TextView tv_number=(TextView) view.findViewById(R.id.tv_number);
            tv_number.setText("电话:"+person.getNumber());
             
            returnview;
            }
            /**
             * 不用inflater
             *
            Log.i(tag, "位置"+position);          //看效果
            TextView tv=new TextView(getApplicationContext());
            tv.setTextSize(20);
            tv.setTextColor(Color.BLACK);
            //每个位置上的条目
            Person person=persons.get(position);
            tv.setText(person.toString());
            return tv;
        }*/
         
    }
}

[2].[文件] 数据库.zip ~ 1MB    下载(33) 跳至 [1] [2]

文件不存在或者代码语言不存在

android基础 sqlite listview activity返回值