我開發應用程序以將動態數據添加到多個表視圖.結構如下.
我在onPostExecute中的代碼是:
protected void onPostExecute(List results){
不能選擇父節點是什么意思。int ind,i = 0;
ScrollView sv=null;
TableLayout tl=null;
TableRow tr = null;
獲取父節點、int mjsonlength=results.size();
if(results!=null){
TableLayout indextl=(TableLayout)findViewById(R.id.indextablelayout);
TableRow indextr=new TableRow(SubProducts.this);
android:layout_margin,//indext1.moveToFirst();
LinearLayout llt=(LinearLayout)findViewById(R.id.alltablell);
//for(int f=0;f
for( ind=0;ind
treeview父節點。{
TextView indextv=new TextView(SubProducts.this);
indextv.setBackgroundResource(R.drawable.greenbg);
indextv.setHeight(25);
多個父節點設計、indextv.setWidth(50);
indextv.setId(6);
indextv.setTextColor(Color.WHITE);
indextv.setText(indextitle.get(ind));
android.intent.category.DEFAULT?indextv.setPadding(20,10,6,3);
indextr.addView(indextv);
indextl.addView(indextr,6);
sv=new ScrollView(SubProducts.this);
android的content?tl=new TableLayout(SubProducts.this);
for( i=0;i
tr=new TableRow(SubProducts.this);
if(ind==i) {
java中append?RelativeLayout rl=new RelativeLayout(SubProducts.this);
Resources res = getResources(); //resource handle
rl.setBackgroundResource(R.drawable.prd_box);
RelativeLayout.LayoutParams newParams1 = new RelativeLayout.LayoutParams(
android fragment切換。RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
image=new ImageView(SubProducts.this);
image.setLayoutParams(newParams1);
image.setId(1);
image.setImageBitmap(bmp);
image.setPadding(5, 20, 5, 5);
rl.addView(image,1);
RelativeLayout.LayoutParams lprams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lprams.addRule(RelativeLayout.RIGHT_OF, 1);
TextView tv1=new TextView(SubProducts.this);
Spanned marked_up = Html.fromHtml(description.get(i));
tv1.setText((marked_up.toString()).substring(1, 170).replaceAll("?",""));
tv1.setLayoutParams(lprams);
tv1.setId(2);
tv1.setHeight(150);
tv1.setWidth(130);
tv1.setPadding(20, 10, 0, 10);
rl.addView(tv1,2);
RelativeLayout.LayoutParams newParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
newParams.addRule(RelativeLayout.BELOW, 2);
TextView tv=new TextView(SubProducts.this);
tv.setText(productname.get(i));
tv.setLayoutParams(newParams);
tv.setTextColor(Color.WHITE);
tv.setId(3);
tv.setPadding(10, 0, 0, 10);
rl.addView(tv,3);
tr.addView(rl);
tr.setPadding(5, 10, 5, 10);
}
tl.addView(tr);
}
sv.addView(tl);
llt.addView(sv);
}
}
}
我得到的錯誤如下:
03-16 06:27:07.452: E/AndroidRuntime(7233): FATAL EXCEPTION: main
03-16 06:27:07.452: E/AndroidRuntime(7233): java.lang.IllegalStateException: The 03-16 06:27:07.452: E/AndroidRuntime(7233): FATAL EXCEPTION: main
03-16 06:27:07.452: E/AndroidRuntime(7233): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.view.ViewGroup.addView(ViewGroup.java:3210)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.widget.TableLayout.addView(TableLayout.java:429)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.view.ViewGroup.addView(ViewGroup.java:3155)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.widget.TableLayout.addView(TableLayout.java:411)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.view.ViewGroup.addView(ViewGroup.java:3131)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.widget.TableLayout.addView(TableLayout.java:402)
03-16 06:27:07.452: E/AndroidRuntime(7233): at com.example.nutritionplusapp.SubProducts$LongRunningGetIO1.onPostExecute(SubProducts.java:227)
03-16 06:27:07.452: E/AndroidRuntime(7233): at com.example.nutritionplusapp.SubProducts$LongRunningGetIO1.onPostExecute(SubProducts.java:1)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.os.Looper.loop(Looper.java:137)
03-16 06:27:07.452: E/AndroidRuntime(7233): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-16 06:27:07.452: E/AndroidRuntime(7233): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 06:27:07.452: E/AndroidRuntime(7233): at java.lang.reflect.Method.invoke(Method.java:511)
03-16 06:27:07.452: E/AndroidRuntime(7233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-16 06:27:07.452: E/AndroidRuntime(7233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-16 06:27:07.452: E/AndroidRuntime(7233): at dalvik.system.NativeStart.main(Native Method)
03-16 06:32:07.586: I/Process(7233): Sending signal. PID: 7233 SIG: 9
03-16 06:32:08.522: E/Trace(7355): error opening trace file: No such file or directory (2)
循環變量值對于兩個循環都應該相同Inorder獲取相應產品的子產品.我正在與上述錯誤作斗爭.任何有想法的人.Plz建議我適當的解決方案.謝謝提前.
編輯:
ArrayList productname=new ArrayList();
ArrayList description=new ArrayList();
ArrayList indextitle=new ArrayList();
ArrayList mStrings = new ArrayList();
在doINBackground下:
JSONObject json = array.getJSONObject(i);
manJson = json.getJSONObject("product");
mStrings.add(manJson.getString("productimage"));
productname.add(manJson.getString("productname"));
indextitle.add(manJson.getString("subcategoryid"));
description.add(manJson.getString("description"));
解決方法:
好的第二個潛在問題也是:
indextl.addView(indextr);
indextr會在每次循環迭代中添加,但它是相同的視圖.您只能將一次視圖添加到層??次結構中.您可能希望每個循環迭代都有一個新實例.我不能肯定地說,但這可能是問題所在.
標簽:android,android-layout
來源: https://codeday.me/bug/20190711/1436529.html
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态