他们看到图片:http://es.tinypic.com/r/mug8b8/8
在拥有一个专栏的月份,有几个人使用boton 类型由查询动态按钮 生成按钮的功能:
private void createEmpresas() {
Button b;
JSONObject json = null;
int count = 0;
LinearLayout lm = (LinearLayout) findViewById(R.id.linearMain);
JSONObject jobj = obj_sqlite.get_descripcion_empresas();
try {
count = Integer.parseInt(jobj.getString("cont"));
json = new JSONObject(jobj.getString("json"));
} catch (Exception e) {
Log.e("getParams", e.getMessage());
}
for (int x = 1; x <= count; x++) {
try {
JSONObject json_row = new JSONObject(json.getString("row" + x));
b = new Button(this);
b.setText(json_row.getString("descripcion"));
b.setId(json_row.getInt("empresa"));
b.setTextSize(10);
b.setPadding(8, 3, 8, 3);
b.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
lm.addView(b);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"Yipee.." +v.getId(), Toast.LENGTH_SHORT)
.show();
}
});
} catch (Exception e) {
Log.e("getParams", e.getMessage());
}
}
}
我的xml是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_main"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.php_mysql_sqlite.MainActivity" >
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button6"
android:layout_alignBottom="@+id/button6"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:background="@null"
android:onClick="loginOut"
android:text="@string/btLogOut"
android:textColor="@color/Red" />
<Button
android:id="@+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button5"
android:layout_alignBottom="@+id/button5"
android:layout_centerHorizontal="true"
android:onClick="syncSqliteMysql"
android:text="@string/syn" />
<Button
android:id="@+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="borrarTabla"
android:text="@string/delTable" />
<ScrollView
android:layout_width="285dp"
android:layout_height="330dp"
android:layout_marginTop="1dp" >
<LinearLayout
android:id="@+id/linearMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="@+id/button5"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button4"
android:background="@color/White"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
感谢您的帮助
PS:如果你给我负分,请留下原因评论,如前所述,而不是为什么