2016-09-26 9 views
0

これは私のコードです。間違いを見つけるのを助けてください。私はListViewのすべてのレクリエーションをロードし、正しく動作しますが、詳細を表示するために1つのレクラメーションをクリックするとレイアウトが表示されますが、情報はtextviewsに表示されません。私はテキストビューでmysqlからデータをロードしようとしています

public class EditReclamationActivity extends Activity { 

       TextView txtName; 

       TextView txtType; 
       TextView txtDesc; 
       String rid; 

       Progress Dialog 
       private ProgressDialog pDialog;     

       JSONParser jsonParser = new JSONParser();     

       private static final String url_reclamation_details = "http://192.168.1.67/android_connect/get_product_details.php"; 

       private static final String TAG_SUCCESS = "success"; 
       private static final String TAG_RECLAMATION = "reclamation"; 
       private static final String TAG_RID = "rid"; 
       private static final String TAG_NAME = "name"; 
       private static final String TAG_TYPE = "type"; 
       private static final String TAG_DESCRIPTION = "description"; 

       @Override 
       public void onCreate(Bundle savedInstanceState) 
       { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.edit_reclamation); 

        Intent i = getIntent();     
        rid = i.getStringExtra(TAG_RID);    

        new GetReclamationDetails().execute(); 

        txtName = (TextView) findViewById(R.id.name1); 
        txtType = (TextView) findViewById(R.id.type1); 
        txtDesc = (TextView) findViewById(R.id.description1);    
       } 
     class GetReclamationDetails extends AsyncTask<String, String, String> {     
       @Override 
       protected void onPreExecute() { 
        super.onPreExecute(); 
        pDialog = new ProgressDialog(EditReclamationActivity.this); 
        pDialog.setMessage("Loading reclamation details. Please wait..."); 
        pDialog.setIndeterminate(false); 
        pDialog.setCancelable(true); 
        pDialog.show();    
       }   

       protected String doInBackground(String... params) {      
          try { 

           List<NameValuePair> pars = new ArrayList<NameValuePair>(); 
           pars.add(new BasicNameValuePair("rid", rid));        

           final JSONObject json = jsonParser.makeHttpRequest(
             url_reclamation_details, "GET", pars);    

           Log.d("Single Rec Details", json.toString()); 
           final int success = json.getInt(TAG_SUCCESS); 
           runOnUiThread(new Runnable() { 
            public void run() {          

             if (success == 1) {    
              try { 

               JSONArray recObj = json.getJSONArray(TAG_RECLAMATION);   

               JSONObject reclamation = recObj.getJSONObject(0);  
               txtName.setText(reclamation.getString(TAG_NAME));       txtType.setText(reclamation.getString(TAG_TYPE));       txtDesc.setText(reclamation.getString(TAG_DESCRIPTION));    

              } catch (JSONException e) { 

              } 
             } else { 

             } 
            } 
           }); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          }     

        return null; 
       }   

       protected void onPostExecute(String file_url) {   
         pDialog.dismiss(); 
       } 
      } 
     } 

This is the message error, data are loaded from mysql but not in android:

答えて

0

あなたがあなたのfindViewsById()new GetReclamationDetails().execute();を呼び出すように見えます。また、あなたのUIをonPostExecuteまたはonProgressUpdateに更新し、あなたのビューを次のように呼び出してみてください:ActivityName.class.yourView.setText()これが役立つことを願っています。

0

メソッドからsettextの前にtextviewを宣言します。

txtName = (TextView) findViewById(R.id.name1); 
txtType = (TextView) findViewById(R.id.type1); 
txtDesc = (TextView) findViewById(R.id.description1); 

new GetReclamationDetails().execute(); 
+0

動作しません – Amine

関連する問題