Textview Casting Error:- Android.widget.linearlayout Cannot Be Cast To Android.widget.textview
Solution 1:
Try this in the constructor for CountriesListAdapter
class:
super(context, R.layout.country_list_item, R.id.txtViewCountryName, values);
instead of:
super(context,R.layout.country_list_item,values);
I just tried it and it worked.
Edit:
I also had to modify your layout as the TextView
was interfering with the ImageView
:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="50dp" ><ImageViewandroid:id="@+id/imgViewFlag"android:layout_width="40dp"android:layout_height="40dp"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"android:layout_centerVertical="true"android:layout_margin="5dp" /><TextViewandroid:id="@+id/txtViewCountryName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toEndOf="@id/imgViewFlag"android:layout_toRightOf="@id/imgViewFlag"android:text="hello"android:textAppearance="@android:style/TextAppearance.Medium.Inverse" /></RelativeLayout>
And the reason why the country images were not showing up in the selector list was because you also have to override getDropDownView
in CountriesListAdapter
and do the same thing that is being done in getView
like so:
@Overridepublic View getDropDownView(int position, View convertView, ViewGroup parent) {
return getView(position, convertView, parent);
}
I tried it with:
values = new String[]{ "CHINA,zh_CN", "JAPAN,ja_JP", "KOREA,ko_KR", "TAIWAN,zh_TW" }
and drawable
resource images zh_cn.png
, ja_jp.png
, ko_kr.png
and zh_tw.png
Solution 2:
Change code String[] g=values[position].split(",");
textView.setText(GetCountryZipCode(g[1]).trim());
To
String[] g=values[position].split(",");
String k= g[1];
textView.setText((GetCountryZipCode[k]).trim());
Post a Comment for "Textview Casting Error:- Android.widget.linearlayout Cannot Be Cast To Android.widget.textview"