创建动态textview资源id以保存php服务器中的值

时间:2016-07-06 11:21:30

标签: php android dynamic resources

创建动态ID以将值保存在php服务器中。每次它应该创建新的TextView id,获取值并将其保存到php mysql db。点击addvip按钮后,它会创建新的TextView

personadd.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View arg0) {
        LayoutInflater layoutInflater =
        (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View addView = layoutInflater.inflate(R.layout.personrowdetail, null);
        TextView textOut = (TextView) addView.findViewById(R.id.textout);
        textOut.setText(peoplehighpostionname.getText().toString() + "," + peoplehightpostionpostion.getText().toString());
        textOut.setId(R.id.textout);
        peoplehighpostionname.setText("");
        peoplehightpostionpostion.setText("");
        Button buttonRemove = (Button) addView.findViewById(R.id.remove);
        buttonRemove.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((LinearLayout) addView.getParent()).removeView(addView);
            }
        });
        containerperson.addView(addView);
                // http://topandroidphones1.blogspot.in/2013/05/add-and-remove-view-dynamically.html
    }
});

personrowdetail.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="wrap_content"
    android:layout_margin="5dp">
    <Button
        android:id="@+id/remove"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Remove"
        android:theme="@style/MyButton"/>
        <TextView
            android:id="@+id/textout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@id/remove"
            android:textSize="20dp"
            />
</RelativeLayout>

mainactivity.xml

<EditText
    android:id="@+id/vip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="VIP Participants"
    android:layout_marginLeft="30dp"
    />
    <Button
        android:id="@+id/vipadd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ADD"
        android:theme="@style/MyButton"
        android:layout_gravity="right|center"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        />
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/containervip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    </LinearLayout>

</LinearLayout>

0 个答案:

没有答案