Change The Textview Style In Androidstudio
I have created a listview called popuplistfragment.java and list_view.xml.I have added textview in xml file but I dont know where to add code to change the textview in the listview
Solution 1:
Firstly you need to extend Adapter class
publicclassListAdapterextendsArrayAdapter<String> {
String [] mQuotes;
publicListAdapter(String [] quotes){
mQuotes = quotes;
}
public View getView(int position, View convertView, ViewGroup parent) {
Viewv= convertView;
if (v == null) {
LayoutInflaterlayoutInflater= LayoutInflater.from(getContext());
v = layoutInflater.inflate(R.layout.itemlistrow, null);
}
TextViewquoteTextView= v.findViewById(R.id.quote_textView);
quoteTextView.setText(mQuotes[position])
return v;
}
@OverridepublicintgetCount() {
return quotes.length;
}
}
Then implement other methods. The next step is to change next code
@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String [] QuoteArray = getResources().getStringArray(R.array.quotes);
ListAdapter adapter = newListAdapter(QuoteArray);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
Then add itemlistrow.xml to Layout folder and change it so:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/quote_textView"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>
You can customize itemlistrow.xml as you want
Post a Comment for "Change The Textview Style In Androidstudio"