How to add row which is having multiple column dynamically in android? - android

Hi I have developed the UI like the screen below.Now I want to add the last row in the UI on last plus button click event.
I know how to add Button or EditText dynamically but I am not getting how can I add and delete row which is having multiple column dynamically.
Edit:- One Important thing about last row is each column is editable.That means I need the reference of each column for getting it's content.When I am adding row dynamically plus button should get placed in new row.Similarly if I remove row row plus button should get shifted to the upper row.
How can I do this.Any guideline or any approach will be appreciated.
This is my XML file.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/navi_bar" />
<Button
android:id="#+id/title_bar_btnBack"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:background="#drawable/back_button_image" />
<Button
android:id="#+id/title_bar_btnExport"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/title_bar_btnBack"
android:layout_marginRight="10dp"
android:background="#drawable/export_button_normal" />
<!-- Create PDF Part 2 -->
<ImageView
android:id="#+id/pdf_Upper_Image"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/title_bar_btnBack"
android:background="#drawable/grid_bg_part1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/pdf_Upper_Image"
android:layout_alignParentLeft="true"
android:text="Kassenbuch"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#3EC7F9"
android:textSize="23dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/textView1"
android:text="Name :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/textView2"
android:text="Akshay"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<!-- Custom Pdf Part 2 -->
<ImageView
android:id="#+id/pdf_Middle_Image"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/pdf_Upper_Image"
android:background="#drawable/grid_bg_part2"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_marginLeft="2dp"
android:text="Einnahmen"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtName"
android:layout_alignTop="#+id/txtName"
android:layout_marginLeft="82dp"
android:layout_toRightOf="#+id/txtName"
android:text="Month :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignLeft="#+id/textView4"
android:layout_marginBottom="2dp"
android:text="Mand Nr. :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/txtMand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView5"
android:layout_alignTop="#+id/textView5"
android:layout_toRightOf="#+id/textView5"
android:text="Mand"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/txtMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtName"
android:layout_alignTop="#+id/textView4"
android:layout_toRightOf="#+id/textView5"
android:text="05"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp"
/>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtYear"
android:layout_alignTop="#+id/txtMonth"
android:layout_toLeftOf="#+id/title_bar_btnExport"
android:text="Year :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignBottom="#+id/textView5"
android:layout_alignLeft="#+id/textView8"
android:text="Blatt :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/txtYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txtMonth"
android:layout_alignLeft="#+id/title_bar_btnExport"
android:layout_alignTop="#+id/txtMonth"
android:text="2012"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/textView3"
android:text="Ausgabne"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9" >
</TextView>
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/textView6"
android:text="Bestand"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_toLeftOf="#+id/txtMand"
android:text="Datum"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9" />
<TextView
android:id="#+id/textView13"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_toLeftOf="#+id/textView5"
android:text="Beleg Konto"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="8dp" />
<TextView
android:id="#+id/textView14"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView13"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_marginRight="03dp"
android:layout_toLeftOf="#+id/textView13"
android:text="Gegen Konto"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="08dp" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/textView14"
android:text="Anfangsbestand/Ubertrag"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="9dp" />
<TextView
android:id="#+id/textView11"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView13"
android:layout_alignTop="#+id/pdf_Middle_Image"
android:layout_marginLeft="25dp"
android:layout_toRightOf="#+id/textView12"
android:text="USt satz."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="09dp" />
<TextView
android:id="#+id/txtBlatt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView9"
android:layout_alignBottom="#+id/textView9"
android:layout_toRightOf="#+id/textView9"
android:text="Blatt"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView11"
android:layout_alignLeft="#+id/textView9"
android:text="Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9" />
<include android:id="#+id/firstRow"
layout="#layout/custom_pdf3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/pdf_Middle_Image"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
Thanks

Create a layout that represents a complete row,then you can use:
public View inflate (int resource, ViewGroup root) from LayoutInflater(a class in android.view package) to Inflate a new view hierarchy from the specified XML resource(for example your new row).
Now you can add this view(your row) dynamically to your main layout with a specific tag(like adding a button dynamically to the layout).

Create an XML layout file, which will represent a 'row in the list view.
Implement a custom Adapter, using base Adapter.
In the getView() method, Inflate the Xml layout, Reference the inner items (using outerLayout.findViewById(), set Listeners right there, and Finally return the view.
Write the implementation for your listener.
Simple enough? :-)

Try creating the whole layout at runtime. Create a single row containgin all ur columns and set visibility of the last one to gone. Change the visibility when the plus button is pressed.
Creating a row of type Relative layout will be good i think. When u want to remove a row Then you will have to count the Relative layouts in the main layout and then remove the index which u want to remove.

I think you will understand best through an example. Lets simplify things a little bit. Lets say your main layout is this:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout" >
</TableLayout>
It's a simple TableLayout without any views yet (You could have pre-baked rows in it). Now you want to create TableRows wich you want to add dinamically, and handle it's subviews separately, right? You could create your whole TableRow in xml:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tablerow_textview"
android:text="Hello" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tablerow_button"
android:text="World" />
</TableRow>
Then the java part. Lets say you want to add 10 of those rows to your TableLayout, and handle each rows button and separately. You can do it like this (You must have access to a Context object):
// get the main TableLayout from xml
TableLayout layout = (TableLayout) findViewById(R.id.main_layout);
// get a LayoutInflater object. 'this' is the current Activity
LayoutInflater inflater = LayoutInflater.from(this);
for(int i=0; i<10; i++)
{
//Create an inflated instance of that layout
TableRow row = (TableRow) inflater.inflate(R.layout.table_row, null);
//Notice, that we call the findViewById() function on the previously
//inflated layout, which means, that we can only access its subviews
Button rowButton = (Button) row.findViewById(R.id.tablerow_button);
TextView rowText = (TextView) row.findViewById(R.id.tablerow_textview);
//Now that you have those Views, you can do whatever you want with them, (set
an onClickListener, change the text, etc)
//finally we need to add the row to the table
layout.addView(row);
}
It would also be a good idea if you wrapper created a class for your inflated layout, with its own getter-setter functions, and you could just instantiate it with the new operator, and all the inflation would be done in the background.

You need to work with custom views. Then each view can be a complex view and you can do what ever you wish, this task should not be easy.
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/textView1"
android:text="Name :"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#3EC7F9"
android:textSize="12dp" />
<com.sample.MyCustomView
android:id="#+id/myView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And then MyCustomView can be Linear Layout or what ever.

In above xml
you did all the things in Textview and adjust that
instead of using that you have to create a Tablelayout in your xml file.
onButtonClick event you have to create a new tablerow dynamically then add components by using tablerow.addview(componentsname) and finally add tablerow to tablelayout
Simple TableLayout

After trying lot of different things I solved my problem like below.I made certain changes in my xml.I used LinearLayout with ScrollView.
And I created one xml file which is having complete row.Now my task is to add that xml in the LinearLayout which I did in the following manner.I am calling this method on button click event at each time.
public void AddDynamicView() {
linearLayout = (LinearLayout) findViewById(R.id.show_pdfTableLayout);
layoutInflater = (LayoutInflater) getApplicationContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.custom_pdf3, null);
linearLayout.addView(view);
list.add(view); // Here I have created list of View so that I can get the id of specific view.
}
I have tried this with TableLayout but I was having some issue with occupying whole row.That's why I had used LinearLayout.

Probably I didn't understand well!!!
You can do everything mentioned in the question using ListView and Adapter.
You can provide an array to hold fields, feed an adapter with the array and feed listView with adapter.
If you need a new Row just add an element to the array.
If you want to delete a Row, just remove it from array.
If you want to sort items, just sort the array.
If you want to select prev/next, just use listview selection method.
I was wondered you checked your answer that is not absolutely correct approach. It's true but if your target ui is complex, the page will need a lot of time to render and scroll than ListViews that is dynamic and optimized.
If you think my answer sounds good, Let me know to update it with some code.

Related

Aligning multiple checkboxes vertically

I try to align four checkboxes but one is not in the center of the other. If I shorten the text it fits but if its longer it looks like in the screenshot. The problem is it will be in different languages so the text size can be different. Also if I remove the scale it fits perfect but I need this bigger checkboxes
This is my code:
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:text="#string/unmounted"
android:textColor="#color/textBlack"
android:layout_below="#+id/abc"
android:layout_toEndOf="#+id/imageView6"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_not_working"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_defective"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/problem_cable_tie"
android:textColor="#color/textBlack"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
Here is the exact solution for your problem, the thing which you are actually trying to achieve is the bigger checkbox view (corresponding to its text which is as big as the checkbox view, obviously) with proper alignment of all the views in the series, something like this:
Your desired UI.
But the thing you are doing wrong is that you are using the scaleX and scaleY attributes for achieving your desired UI that distorts your view as these two attributes scale the complete view i.e. the squared checkbox view with its text/label in the X and Y directions respectively (together with the text/label of the checkbox), so there is a dependency on the text as well (which is distorting your view).
So, the below code will solve your problem:
(In this I have taken the squared checkbox view as separate and beside it I have placed a textview in which I have written the text which corresponds to the text/label of that checkbox to complete the UI). Thereby using two views (i.e. the CheckBox and the TextView beside it) instead of using a single compound view (i.e. the CheckBox).
Note: In the solution given below, the CheckBox is a compound view but I haven't used it in the
same manner.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/some_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp" />
<!--android:text="Unmounted"-->
<CheckBox
android:id="#+id/cb1"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_below="#+id/some_view"
android:layout_alignStart="#+id/some_view"
android:focusable="false" />
<TextView
android:id="#+id/tv_for_cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb1"
android:layout_alignTop="#+id/cb1"
android:layout_alignBottom="#+id/cb1"
android:layout_marginStart="40dp"
android:text="Unmounted"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Not Working"-->
<CheckBox
android:id="#+id/cb2"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb1"
android:layout_alignStart="#+id/cb1"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb2"
android:layout_alignTop="#+id/cb2"
android:layout_alignBottom="#+id/cb2"
android:layout_marginStart="40dp"
android:text="Problem Not Working"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Defective"-->
<CheckBox
android:id="#+id/cb3"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb2"
android:layout_alignStart="#+id/cb2"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb3"
android:layout_alignTop="#+id/cb3"
android:layout_alignBottom="#+id/cb3"
android:layout_marginStart="40dp"
android:text="Problem Cable Defective"
android:textColor="#android:color/black"
android:textSize="24sp" />
<!--android:text="Problem Cable Tie"-->
<CheckBox
android:id="#+id/cb4"
android:scaleX="1.3"
android:scaleY="1.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_below="#+id/cb3"
android:layout_alignStart="#+id/cb3"
android:focusable="false"/>
<TextView
android:id="#+id/tv_for_cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#id/cb4"
android:layout_alignTop="#+id/cb4"
android:layout_alignBottom="#+id/cb4"
android:layout_marginStart="40dp"
android:text="Problem Cable Tie"
android:textColor="#android:color/black"
android:textSize="24sp" />
</RelativeLayout>
And the other way out to your mentioned problem would be to create custom drawables for the checkbox and then handle them using a state list drawable as for the checkbox to be shown differently in different states as when it is unchecked, checked etc.
This link would help you if you are interested in doing it in this manner or way and would be great if you want to customize your checkbox's view.
Creating custom checkbox using selectors and shapes.
For further help in this context refer:
Android: How to change CheckBox size?

how to rearrange my textview in my relativelayout?

Here's my layout screenshot:
How can I arrange all these TextView for them to have a good format (heading being Taking responsibility (means being aware)..) alignment etc.
<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"
tools:context=".Menu"
android:background="#android:color/holo_blue_bright"
>
<TextView
android:text="*Follow safety guide for moving around the town and between towns."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="51dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp" />
<TextView
android:text="*Avoid crowds and do not participate actively in demonstrations even when it is related to programme work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView25"
android:gravity="left"
android:layout_marginBottom="23dp"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25" />
<TextView
android:text="*keep this briefing pack in an accessible place, and the emergency numbers in your mobile phone memory"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_above="#+id/textView25"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_marginBottom="46dp" />
<TextView
android:gravity="center"
android:textColor="#000"
android:textSize="15dp"
android:text="Taking resposibility(means being aware)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView22"
android:layout_marginTop="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Avoid moving around town by yourself and always make others aware of your location."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/textView25"
android:layout_marginTop="76dp"
android:layout_below="#+id/textView22"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="*Share any security information that might have implications for Ballloon Ventures to the Country Manager or pc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView24"
android:gravity="left"
android:layout_below="#+id/textView26"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:text="*If using host home accommondation,check that it is secure.if it is not,tell the Programme Coordinator"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:id="#+id/textView28"
android:layout_marginTop="14dp"
android:layout_below="#+id/textView24"
android:layout_alignRight="#+id/textView25"
android:layout_alignEnd="#+id/textView25" />
<TextView
android:text="*Report all incidents to your Programmer Cordinator."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView26"
android:gravity="left"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
</RelativeLayout>
Because if I drag one TextView it affecting all other TextView.
As #GabeSechan said, you need to learn what android:layout_xxx properties in RelativeLayout means.
When you moving a View in RelativeLayout via Layout Editor, you need to consider some of the following properties in your layout:
android:layout_above="#+id/textView25"
android:layout_below="#+id/textView24"
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView25" means that you want the View above textView25 view.
android:layout_below="#+id/textView24" means that you want the View below textView25 View.
The following properties means that you want the view to the right side of TextView25 View:
android:layout_toRightOf="#+id/textView25"
android:layout_toEndOf="#+id/textView25"
The following properties means that you want the view to align with the left side of the parent layout:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
If you want to edit views position in a RelativeLayout, please don't depends with drag and drop via Layout Editor. You better do it manually except you want to have a headache later. Use Layout Editor to view the design result.
Design with a paper or imagination first, then code it after that.
Try to learn it from:
Relative Layout
Constructing View Layouts
The best practice for doing that would be to open a splitview between your code and design views and then editing the code to place the text in the correct location, using attributes such as padding, margin, aligning, below, above, etc. refer to this guide for positioning stuff in relative layout and combine it with other formatting attributes such as margin and padding.

how to random button when activity start

I would like to know on how to randomly the button when activity start.
I have 5 button as bellow code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom|center">
<Button
android:id="#+id/q1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
android:background="#drawable/ic_btn_q_normal" />
<Button
android:id="#+id/q2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
android:background="#drawable/ic_btn_q_normal" />
<Button
android:id="#+id/q3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
android:background="#drawable/ic_btn_q_normal" />
<Button
android:id="#+id/q4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
android:background="#drawable/ic_btn_q_normal" />
<Button
android:id="#+id/q5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
android:background="#drawable/ic_btn_q_normal" />
</LinearLayout>
So, how can I random it when activity start.
Let's say I start activity 3 times:
1st start activity, button will be list as horizontal like as q1/q2/q3/q4/q5
2st start activity, button will be list as horizontal like as q4/q2/q1/q3/q5
3st start activity, button will be list as horizontal like as q1/q5/q2/q4/q3
Like this.
Thanks you
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. All children of a LinearLayout are stacked one after the other.
My guess is you want to display some buttons randomly on a layout. So I suggest you to work whether with RelativeLayout because you can move children easily or to build your Layout directly in the Java implementation (generate a Random or use Collection.shuffle(List).

android layout with visibility GONE

Four views are using same xml. I want to show a linear layout for view 1 only.
I put android:visibility="gone" in xml. And then I am doing the following for view 1-
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);
layone.setVisibility(View.VISIBLE);
But that doesn't set the visibility to visible.
Isn't it possible to show the view once its declared GONE in xml ?
I don't want to converse the logic by just doing,
layone.setVisibility(View.GONE);
in each of the three views except view 1.
Ideas or comments?
UPDATE:
My xml -
<TextView
android:id="#+id/layone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="16dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:tag="PrevEntries"
android:id="#+id/laytwo"
android:layout_marginTop="10dp"
android:background="#layout/roundedtext"
android:visibility="gone" >
<TextView
android:id="#+id/laythree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="18dp"
android:gravity="center"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/layone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous Page"
android:textColor="#000000"
android:textSize="16dp"
android:paddingLeft="10dp"
android:layout_marginTop="10dp"
android:visibility="gone" />
layone is a TextView.
You got your id wrong.
LinearLayout layone= (LinearLayout) view.findViewById(R.id.laytwo);// change id here
layone.setVisibility(View.VISIBLE);
should do the job.
or change like this to show the TextView:
TextView layone= (TextView) view.findViewById(R.id.layone);
layone.setVisibility(View.VISIBLE);
Done by having it like that:
view = inflater.inflate(R.layout.entry_detail, container, false);
TextView tp1= (TextView) view.findViewById(R.id.tp1);
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);
tp1.setVisibility(View.VISIBLE);
layone.setVisibility(View.VISIBLE);
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/activity_register_header"
android:minHeight="50dp"
android:orientation="vertical"
android:visibility="gone" />
Try this piece of code..For me this code worked..
Kotlin Style way to do this more simple (example):
isVisible = false
Complete example:
if (some_data_array.details == null){
holder.view.some_data_array.isVisible = false}
put this attribute in your xml view for Gone
android:visibility="gone"
put this attribute in your xml view for Show
android:visibility="visible"
Example
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/futura_medium_bt"
android:text="•Unlock all graphics"
android:textAllCaps="true"
android:visibility="gone"
android:textColor="#color/black"
android:textSize="#dimen/_12ssp" />

How to invisible line in list view for android Honey comb

I m creating an app in that app i want to invisible this Mr. bla bla two line when i clicked on chat image.
any suggestion will be appriciate.
thanks in advance.
this is my xml file.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_frag_list_message_layout"
android:background="#EBEBEB"
android:layout_marginBottom="10dp"
android:descendantFocusability ="blocksDescendants"
android:layout_marginTop="10dp"
android:layout_below="#+id/task_list_text"
android:layout_marginLeft="80dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion1"
android:text="Mr. Test : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text1"
android:text="A send you a data file kindly get it."
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_toRightOf="#+id/task_list_chat_persion1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_persion2"
android:text="Mr. me : "
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:textColor="#color/sky_blue_color"
/>
<TextView android:textColor="#color/black_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/task_list_chat_text2"
android:text="I got the data file and i have some doubt in them"
android:textSize="18dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/task_list_chat_persion1"
android:layout_toRightOf="#+id/task_list_chat_persion2"
/>
</RelativeLayout>
this two lines are ij relative latout.
I think you want this ...
just need to add onClick() event on chat image and then on clicking set visibility of TextView to invisible by code.
TextView _text= (TextView)findViewById(R.id.task_list_chat_text);
_text.setVisibility(TextView.INVISIBLE);
When you click on chat button in the list view you should setTest="" blank for both remove it.
It may be solution of this problem.

Categories

Resources