How to get value onListItemClick and pass it to another activity

前端 未结 2 1496
北海茫月
北海茫月 2021-01-06 00:00

I have a listView which has information inside and when i click one row it must give me all the details under that selected row , in that select row i have image, imagename,

2条回答
  •  孤街浪徒
    2021-01-06 00:45

    I was trying this code for two days now, then I got it, so here it goes.. OnListItemClick will pass a position :

    @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
    
            String selectedValue = (String) getListAdapter().getItem(position);
            Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
    
    Intent moreDetailsIntent = new Intent(ListMobileActivity.this,PropertiesDetails.class);
    
            Bundle dataBundle = new Bundle();
            dataBundle.putString("SelectedProperty", selectedValue);
            moreDetailsIntent.putExtras(dataBundle);
            startActivity(moreDetailsIntent);
    
    
        }
    

    Then second class will receive that values including a image :

    String Price,Desc,City,rooms,address,size,garage,sold,Pname,image1,image2,image3;
        Bitmap bitmap,bitmap1,bitmap2,bitmap3;
        TextView txtPrice,txtDesc,txtCity,txtrooms,txtaddress,txtsize,txtgarage,txtsold;
        ImageView imgpropertyImage,imgpropertyImage2;
        String result = null;
        InputStream is = null; 
        StringBuilder sb=null;
        Button btnNext,btnPrevs;
        int imgcount = 1;
        JSONPARSER jsonParser = new JSONPARSER();
        private static String url_create_product = "http://10.0.2.2/php/ViewPropertiesByName.php";
        // JSON Node names
       // private static final String TAG_SUCCESS = "success";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.thenew);
    
            txtPrice = (TextView) findViewById(R.id.price);
            txtDesc = (TextView) findViewById(R.id.desc);
            txtCity  = (TextView) findViewById(R.id.City);
            txtrooms = (TextView) findViewById(R.id.Rooms);
            txtaddress = (TextView) findViewById(R.id.Address);
            txtsize  = (TextView) findViewById(R.id.Size);
            txtgarage  = (TextView) findViewById(R.id.garage);
        //  txtsold  = (TextView) findViewById(R.id.sold);      
            imgpropertyImage = (ImageView) findViewById(R.id.imageViewProp);
            imgpropertyImage2 = (ImageView) findViewById(R.id.imageViewProp2);
            btnNext =(Button) findViewById(R.id.btnNext);
            btnPrevs =(Button) findViewById(R.id.btnPrevis);
    
    
    
    
    
    Bundle b = getIntent().getExtras(); // Getting the Bundle object that pass from another activity
    String SelectedProperty = b.getString("SelectedProperty");
    
    ////////////////////////Executing A Search Query//////////////////////////////////
    List postParameters = new ArrayList();
    postParameters.add(new BasicNameValuePair("P_City",SelectedProperty));
    
    //getting JSON Object
    // Note that create product url accepts POST method
     JSONObject json = jsonParser.makeHttpRequest(url_create_product,
             "POST", postParameters);
    // check log cat fro response
    Log.d("Create Response", json.toString());
    
    
    
    /////////////Getting Jason Object from the search Query and displaying results
    try{
    
        JSONArray  earthquakes = json.getJSONArray("PropertyDetails");
    
        for(int i=0;i

    I helping those who will have same problem as mine in future :)

提交回复
热议问题