Я создаю Linear Layout в своем приложении, используя LayoutInflater
. Значение для этого элемента, которое я привезу из Jason и меня, изменит значение в методе run.Обновление Android LinearLayout в Thread и Runnable
public void run()
{
/**
* Updating parsed JSON data into ListView
**/
// coNa .setText(productsList.get(0));
// coId.setText(productsList.get(1));
}
Я создал его в onCreate
функции, но приложение получает исключение, когда значение изменяется.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.studenttablemain);
ll = (LinearLayout) findViewById(R.id.ll);
for (int i=0;i<5;i++){
View view = LayoutInflater.from(this).inflate(R.layout.studanttableitem,null);
TextView coNa = (TextView)findViewById(R.id.coursename);
TextView coId = (TextView)findViewById(R.id.courseid);
TextView teacherid = (TextView)findViewById(R.id.teachername);
TextView day = (TextView)findViewById(R.id.days);
TextView time = (TextView)findViewById(R.id.time);
TextView hole = (TextView)findViewById(R.id.hole);
// Assigning value to imageview and textview here
ll.addView(view);
}
new LoadAllProducts().execute();
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CopyOfstudanttable.this);
pDialog.setMessage("Loading information . Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("studant: ", json.toString());
String name="";
String sid="";
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
//for (int i = 0; i < products.length(); i++) {
Log.d("length", "-"+products.length()+"-item");
JSONObject c = products.getJSONObject(0);
// Storing each json item in variable
//String id = c.getString(TAG_PID);
name = c.getString(TAG_NAME);
sid = c.getString(TAG_SID);
Log.d("name", "-"+c.getString(TAG_NAME)+"-item");
Log.d("id", "-"+c.getString(TAG_SID)+"-item");
productsList.add(name);
productsList.add(sid);
// }
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
LogIn.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.toString();
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
// coNa .setText(productsList.get(0));
// coId.setText(productsList.get(1));
}
});
}
}
где находится код ?? JSON –
, что важно для json cod результат возврата в \t JSONObject c = products.getJSONObject (0); \t \t \t \t \t \t // Сохранение каждого элемента в переменной JSon \t \t \t \t \t \t // Строка ID = c.getString (TAG_PID); \t \t \t \t \t \t name = c.getString (TAG_NAME); \t \t \t \t \t \t sid = c.getString (TAG_SID); –