나는 웹 페이지에서 제품 목록을 얻는 함수를 가지고 있으며 목록의 각 요소에 대해 tableLayout에 행을 추가하려고합니다. 내 레이아웃 XML 파일에안드로이드에서 tableLayout에 행을 동적으로 추가하는 방법
public void getProductsOfCategory() throws IOException{
new Thread(){
public void run(){
//background code...
try {
Bundle extras = getIntent().getExtras();
String categoryName = extras.getString("categoryName");
HttpGet httpget = new HttpGet("http://romal.hopto.org/foodadvisor/users/getProductsOfCategory.json?category="+categoryName);
HttpResponse httpresp = httpClient.execute(httpget);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
httpresp.getEntity().writeTo(baos);
final String content = new String(baos.toByteArray());
CategoryActivity.this.runOnUiThread(new Runnable(){
public void run(){
//foreground code (UI)
//update user interface, for example, showing messages
try {
JSONObject jObject = new JSONObject(content);
JSONArray productsList = jObject.getJSONArray("response");
for(int i=0; i<productsList.length();i++){
JSONObject product = productsList.getJSONObject(i);
JSONObject productData = product.getJSONObject("Product");
String productDescription = productData.getString("description");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
나는 다음과 같은 테이블 레이아웃을 정의했습니다 :
<TableLayout
android:id="@+id/tableOfProducts"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/productDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:paddingBottom="7dp"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="7dp"
android:textSize="20dp" />
</TableLayout>
가 내가 새 행과 새로운 텍스트 뷰를 추가, 루프에 대한 일부 추가 코드를 추가 할 필요가 상상 제품의 설명이있는. 자열로 텍스트보기의 내용을 설정하십시오. 어떻게해야합니까? 이것에 대한
@JuanPedroMartinez 누구나 이해할 수 있도록 영어로 의견을 말하십시오. – Aniruddha
그는 당신이 훌륭한 일을했다고 말합니다. 그러나, 그것은 나에게 오류를주고, 나는 그것을 해결하는 방법을 모른다. :) – Julia
오케이, 무엇이 오류입니까? – Aniruddha