Reputation: 2362
I am using following layout for my list view items.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheme.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:textSize="18sp"
android:minHeight="40sp"
/>
But I am getting an error in the logcat java.lang.RuntimeException ... that you must supply a layout_width argument.
My main.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget28"
android:background="#ff000033"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="70px"
android:layout_height="30px"
android:paddingLeft="2px"
android:paddingTop="2px"
android:background="@drawable/ic_launcher"
></ImageView>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
and this is my activity's onCreate code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context=this.getApplicationContext();
this.setTitle("NP Headline News");
myListView=(ListView)findViewById(R.id.myListView);
myListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View v, int index,long id) {
// TODO Auto-generated method stub
String urlAddress=urlAddresses[index];
String urlCaption = urlsCaptions[index];
}
});
int layoutId=R.layout.simple_list_item_1;
// int layoutId=android.R.layout.simple_list_item_1;
aa = new ArrayAdapter<String>(this,layoutId,this.urlsCaptions);
myListView.setAdapter(aa);
}
I think that it is something related to my simple_list_item_1 because if I use android.R.layout.simple_list_item_1 then every thing works ok
Upvotes: 0
Views: 208
Reputation: 3221
Here is your error cleared layout:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:textSize="18sp"
android:minHeight="40sp"
/>
Can you able to differentiate your error contained code and this above one.
I wish you guys to don't tense and urge while code something, that must be lead you to blocked and confused minded.
For these type of errors, you could use to debug yourself with the help of DDMS. Because the code is very very simple to view right.
And some words about the previous answers:
Guys that is not necessary to declare a TextView
or any View
only inside of the Layout
file.
It is also a View
, So it can capable to sit alone in a Canvas
.
And also the problem is not by the "fill_parent"
, and "match_parent"
Something.
I think you might be tensed now also, because i am taking this much time to give you the reason of your error.
Here we go,
the error is because simply in the following line,
xmlns:android="http://schemas.android.com/apk/res/android"
In the above line you mistakenly typed scheme
instead of schemas
.
That is the error.
So only i mentioned if you had look at the code with out tense you can get it easily.
xmlns
denotes the namespace , that should be proper in order make the android:
prefixed attributes as valuable.
Hope you understand and the answer helpful to you.
Upvotes: 2
Reputation: 9608
I guess problem comes from something different.
You are doing a custom item view, but you use standard AdapterView.
For a standard arrayAdapter you need to fulfil the expected structure.
Alternatively you build an own ArrayAdapter and supply your dedicated getView
Upvotes: 0
Reputation: 1200
YOU should puy your TextView under a Layout, since your are using a unique TextView you could add a LinearLayout
<?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" >
<TextView xmlns:android="http://scheme.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:textSize="18sp"
android:minHeight="40sp"
/>
</LinearLayout>
Upvotes: 0