In this example creating some UI elements on screen on run time.
XML Code:
Java Code:
XML Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shadow_common"
android:padding="5dp"
android:orientation="horizontal"
android:visibility="visible">
<RelativeLayout
android:id="@+id/closelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/textLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center"
android:padding="5dp"
android:textSize="12dp"
android:text="Aminities" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/textLayout" >
<TextView
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circul_shape_black"
android:gravity="center"
android:text=""
android:textColor="@android:color/black"
android:textSize="8sp" />
<ImageView
android:id="@+id/editfont"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@android:drawable/ic_delete"
android:textSize="8dp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Java Code:
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txt=text.getText().toString();
flowContainer.setVisibility(View.VISIBLE);
flowContainer.setOrientation(LinearLayout.VERTICAL);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.view_locality_selection, null);
TextView textOut = (TextView) addView.findViewById(R.id.textout);
textOut.setText("" + txt);
text.setText("");
addView.setTag(txt);
//Typeface font = Typeface.createFromAsset(getAssets(), "fonts/AndroidFont.ttf");
RelativeLayout buttonCLick = (RelativeLayout) addView.findViewById(R.id.closelayout);
ImageView buttonRemove = (ImageView) addView.findViewById(R.id.editfont);
//buttonRemove.setTypeface(font);
buttonCLick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
flowContainer.removeView(addView);
String s = addView.getTag().toString();
}
});
flowContainer.addView(addView);
}
});
To get Full code:
No comments:
Post a Comment