Android - ANDROID - OnItemClick en ListView AYUDA URGENTE!!!

   
Vista:
Imágen de perfil de Carl

ANDROID - OnItemClick en ListView AYUDA URGENTE!!!

Publicado por Carl (7 intervenciones) el 28/10/2015 06:11:37
Hola.
Mi código actual no me permite hacer click en algun elemento y este pueda enviar data a otro intent.

Estaba probando... y nunca me funcionaba.
Espero puedan ayudarme por favor. Saludos.




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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
public class UiMainActivity extends AppCompatActivity {
    String myJSON;
 
    private static final String TAG_RESULTS = "result";
    private static final String TAG_PROCODE = "pro_code";
    private static final String TAG_PRONAME = "pro_name";
    private static final String TAG_PRODETAIL = "pro_detail";
    public final static String ARG_PROCODE = "ARG_PROCODE";
    JSONArray peoples = null;
 
    ArrayList<HashMap<String, String>> personList;
 
    ListView list;
 
    public String tvProCode;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ui_main);
        list = (ListView) findViewById(R.id.lvProject);
        personList = new ArrayList<HashMap<String, String>>();
        getData();
 
 
    }
 
 
    protected void showList() {
        try {
            JSONObject jsonObj = new JSONObject(myJSON);
            peoples = jsonObj.getJSONArray(TAG_RESULTS);
 
            for (int i = 0; i < peoples.length(); i++) {
                JSONObject c = peoples.getJSONObject(i);
                String id = c.getString(TAG_PROCODE);
                String name = c.getString(TAG_PRONAME);
                String address = c.getString(TAG_PRODETAIL);
 
                HashMap<String, String> persons = new HashMap<String, String>();
 
                persons.put(TAG_PROCODE, id);
                persons.put(TAG_PRONAME, name);
                persons.put(TAG_PRODETAIL, address);
 
                personList.add(persons);
            }
 
            ListAdapter adapter = new SimpleAdapter(
                    UiMainActivity.this, personList, R.layout.item_project,
                    new String[]{TAG_PROCODE, TAG_PRONAME, TAG_PRODETAIL},
                    new int[]{R.id.tvProCode, R.id.tvProName, R.id.tvProDetail}
            );
            list.setAdapter(adapter);
 
 
 
            //Este codigo estaba implementado pero aun asi no me funciona.
            ListView listView1 = (ListView) findViewById(R.id.lvProject);
            listView1.setAdapter(adapter);
 
            listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position,
                                        long id) {
 
                    String item = ((TextView) view).getText().toString();
 
                    Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
 
                }
            });
 
 
        } catch (JSONException e) {
            e.printStackTrace();
        }
 
 
    }
 
 
 
 
    //AdapterView.OnItemClickListener newOnItemClickListener() {
 
    //Toast.makeText(getApplicationContext(), "Mensaje de toast :D.",Toast.LENGTH_SHORT).show();
    //return null;
    //}
 
 
    public void getData() {
        class GetDataJSON extends AsyncTask<String, Void, String> {
 
            @Override
            protected String doInBackground(String... params) {
                DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
                HttpPost httppost = new HttpPost("http://192.168.1.41:8080/MyProjects/android/AndroidProject/dao/project.php");
 
                // Depends on your web service
                httppost.setHeader("Content-type", "application/json");
 
                InputStream inputStream = null;
                String result = null;
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
 
                    inputStream = entity.getContent();
                    // json is UTF-8 by default
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();
 
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (Exception e) {
                    // Oops
                } finally {
                    try {
                        if (inputStream != null) inputStream.close();
                    } catch (Exception squish) {
                    }
                }
                return result;
            }
 
            @Override
            protected void onPostExecute(String result) {
                myJSON = result;
                showList();
            }
        }
        GetDataJSON g = new GetDataJSON();
        g.execute();
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_ui_main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
 
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
 
        return super.onOptionsItemSelected(item);
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder