i have created three linear layouts of equal weights. Inside one of the linear layouts i have 6 text views. I have initialized the text view in my activity. But i'm not able to view this text view. I don't know where i'm going wrong. Please help me.
This is my XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/lay"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<TextView android:id="@+id/num1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="10dip"
android:layout_weight="1" />
<TextView android:id="@+id/date1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="#000000"
android:textSize="10dip"
android:layout_marginLeft="10dp"
android:layout_weight="1" />
<TextView android:id="@+id/cus1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="10dip" />
<TextView android:id="@+id/service1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="10dip" />
<TextView android:id="@+id/job1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="10dip" />
<TextView android:id="@+id/des1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="10dip" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#FFFFFF" >
<EditText
android:id="@+id/EditTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/followup"
android:inputType="textMultiLine"
android:lines="3" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#FFFFFF" />
</LinearLayout>
This is my activity
public class Detail extends Activity{
String value1 , value2;
Cursor c, c1;
DataBaseHelper myDbHelper = new DataBaseHelper(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
LinearLayout ll = (LinearLayout) findViewById(R.id.lay);
TextView tv1 =(TextView)ll.findViewById(R.id.num1);
TextView tv2 =(TextView)ll.findViewById(R.id.date1);
TextView tv3 =(TextView)ll.findViewById(R.id.cus1);
TextView tv4 =(TextView)ll.findViewById(R.id.service1);
TextView tv5 =(TextView)ll.findViewById(R.id.job1);
TextView tv6 =(TextView)ll.findViewById(R.id.des1);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
value1 = extras.getString("keyName");
value2 = extras.getString("keyTime");
}
try {
myDbHelper.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
myDbHelper.setSearch(value1);
c = myDbHelper.getDetail();
if(c.getCount()!=0){
c.moveToFirst();
while (!c.isAfterLast()) {
tv1.setText("Ticket No:" + c.getString(c.getColumnIndex("taskID")));
tv2.setText("Date:" + value2 + "/" + c.getString(c.getColumnIndex("time")) );
tv3.setText("Customer Name:" + value1);
tv4.setText("Description:" + c.getString(c.getColumnIndex("taskDetail")));
c.moveToNext();
}
c.close();
}
myDbHelper.setSearch(value1);
c1 = myDbHelper.getService();
if(c1.getCount()!=0){
c1.moveToFirst();
while (!c1.isAfterLast()) {
tv5.setText("Service Type:" + c1.getString(c1.getColumnIndex("description")));
tv6.setText(value1);
c1.moveToNext();
}
c1.close();
}
myDbHelper.close();}}
I want a layout like this,
First two text in the same line one at the right and another at the left corner, the other four vertically down. How to achieve this?
You've set the layout_width
attribute TextView
s to be 0dip
, but only two of the six of them have a layout_weight
attribute. The other four will have a zero width.
Either:
TextView
s to have a width > 0dip
...layout_width
attribute to the remaining four TextView
s, just as you did with the first two.Edit as per comments:
<LinearLayout
...
android:orientation="vertical">
<LinearLayout
...
android:orientation="horizontal">
<TextView />
<TextView />
</LinearLayout>
<LinearLayout
...
android:orientation="vertical">
<TextView />
<TextView />
<TextView />
<TextView />
</LinearLayout>
</LinearLayout>
This is just a basic draft so you get an idea of what layouts belong where. Remember to set your layout weights, widths, heights, IDs, etc, etc, etc.