質問編集履歴
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,94 @@
|
|
1
1
|
ListViewを使っていくつかの文字列を並べた後に、そこをタップすると画面遷移する処理を書きたいです。
|
2
2
|
|
3
|
+
``` package com.example.sample.name;
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
import android.content.Intent;
|
8
|
+
|
9
|
+
import android.support.v7.app.AppCompatActivity;
|
10
|
+
|
11
|
+
import android.os.Bundle;
|
12
|
+
|
13
|
+
import android.view.View;
|
14
|
+
|
15
|
+
import android.widget.AdapterView;
|
16
|
+
|
17
|
+
import android.widget.ArrayAdapter;
|
18
|
+
|
19
|
+
import android.widget.ListView;
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
import java.util.ArrayList;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
public class I extends AppCompatActivity {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
@Override
|
32
|
+
|
33
|
+
protected void onCreate(Bundle savedInstanceState) {
|
34
|
+
|
35
|
+
super.onCreate(savedInstanceState);
|
36
|
+
|
37
|
+
setContentView(R.layout.activity_i);
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
ListView iListView = (ListView) findViewById(R.id.iList);
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
ArrayList<String> ilist_items = new ArrayList<>();
|
46
|
+
|
47
|
+
String[] ititle = {
|
48
|
+
|
49
|
+
"@string/i1",
|
50
|
+
|
51
|
+
"@string/i2",
|
52
|
+
|
53
|
+
"@string/i3",
|
54
|
+
|
55
|
+
"@string/i4",
|
56
|
+
|
57
|
+
"@string/i5"
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
for (int i = 0; i < ititle.length; i++) {
|
62
|
+
|
63
|
+
ilist_items.add(ititle[i]);
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
|
68
|
+
|
69
|
+
this,
|
70
|
+
|
71
|
+
R.layout.ilist_item,
|
72
|
+
|
73
|
+
ilist_items
|
74
|
+
|
75
|
+
);
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
iListView.setAdapter(adapter);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
iListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
84
|
+
|
85
|
+
@Override
|
86
|
+
|
3
|
-
|
87
|
+
public void onItemClick(
|
4
88
|
|
5
89
|
AdapterView<?> adapterView,
|
6
90
|
|
7
|
-
View view,
|
91
|
+
View view,
|
8
92
|
|
9
93
|
int i,
|
10
94
|
|
@@ -18,6 +102,12 @@
|
|
18
102
|
|
19
103
|
}
|
20
104
|
|
105
|
+
});
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
21
111
|
コード
|
22
112
|
|
23
113
|
```
|