2017-12-09 7 views
-1

이 코드는 listView에서 wamp 서버를 사용하여 데이터베이스에서 데이터를 가져 오지만 클릭해야합니다. 나는 2를 클릭하면 행 # 1은 두 번째 활동에 행 # 1을 보여줍니다, 그것은listView에서 동일한 데이터를 표시 할 수있는 방법은 안드로이드에서 두 번째 활동을 보여줄 수 있습니다. google을 클릭하면 두 번째 활동이 Google에 표시됩니다.

import android.content.Intent; 
import android.graphics.Color; 
import android.os.AsyncTask; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.io.BufferedReader; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 

public class attendence extends AppCompatActivity { 

    ListView listView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_attendence); 

     String name = getIntent().getExtras().getString("username"); 
     getJSON("http://192.168.0.102/A/select.php" + "?username=" + name); 
     listView = (ListView) findViewById(R.id.LV); 

     // TextView txtname = (TextView) findViewById(R.id.txt_success_name); 
     // 
     // Intent intent = getIntent(); 
     // String loginName = intent.getStringExtra("username"); 
     // txtname.setText("Welcome, " +loginName); 
    } 

    private void getJSON(final String urlWebService) { 

     class GetJSON extends AsyncTask<Void, Void, String> { 

      @Override 
      protected void onPreExecute() { 
       super.onPreExecute(); 
      } 

      @Override 
      protected void onPostExecute(String s) { 
       super.onPostExecute(s); 
       Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); 
       try { 

        loadIntoListView(s); 
       } catch (JSONException e) { 

        e.printStackTrace(); 
       } 
      } 

      @Override 
      protected String doInBackground(Void... voids) { 
       try { 
        URL url = new URL(urlWebService); 
        HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
        StringBuilder sb = new StringBuilder(); 
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream())); 
        String json; 
        while ((json = bufferedReader.readLine()) != null) { 
         sb.append(json + "\n"); 
        } 
        return sb.toString().trim(); 
       } catch (Exception e) { 
        return null; 
       } 
      } 
     } 
     GetJSON getJSON = new GetJSON(); 
     getJSON.execute(); 

    } 

    // 
    private void loadIntoListView(String json) throws JSONException { 
     JSONObject object = new JSONObject(json); 
     JSONArray jsonArray = object.getJSONArray("Result"); 
     String[] heroes = new String[jsonArray.length()]; 
     for (int i = 0; i < jsonArray.length(); i++) { 
      JSONObject obj = jsonArray.getJSONObject(i); 
      heroes[i] = obj.getString("ID") + " " + obj.getString("STATUS") + " " + obj.getString("ATD_DATE"); 
      if (!obj.getString("STATUS").toString().equals("A")) { 
       listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
        @Override 
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
         Intent i = new Intent(attendence.this, atd_leave_form.class); 
         startActivity(i); 
        } 
       }); 
      } else { 

      } 

      // Toast.makeText(getApplication(),"GREEN",Toast.LENGTH_LONG).show(); 
      // listView.setBackgroundColor(Color.GREEN); 
     } 
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, heroes); 
     listView.setAdapter(arrayAdapter); 
    } 
} 

가 난 그냥에서 목록보기를 클릭하는 동일한 단일 데이터를 표시하려면, 두 번째 활동에 행 # 2를 보여줍니다 기계적 인조 인간. 도움을 미리 요청 해주세요.

답변