0

How can I replace my basic adapter with custom adapter.Here I didn't change my code to custom adapter. As to my code how should I replace basic adapter with custom adapter to get the messages dynamically into custom adapter. Below I have attached my codes,`

String[] monthsArray={
        "https://www.google.co.in/maps?geo:0,0?q=my+street+address?geo:latitude,longitude"
};
 mHistoryList = new ArrayAdapter<String>(this, android.R.layout.test_list_item);
    //CustomListAdapter mHistoryList=new CustomListAdapter(this,links);
    ListView hlv = (ListView) findViewById(R.id.useHistoryList);
    hlv.setAdapter(mHistoryList);

CustomAdapter Code,

CustomListAdapter mHistoryList=new CustomListAdapter(this,monthsArray);
        ListView list=(ListView)findViewById(R.id.useHistoryList);
           list.setAdapter(mHistoryList);
           list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              String SelectedItem=monthsArray[+position];
            Toast.makeText(getApplicationContext(),SelectedItem,Toast.LENGTH_SHORT).show();

CustomAdapter.Java file,

private final Context context;
private final String[] links;


public CustomListAdapter(Context context, String[] links) {
    super(context,0,links);

    this.context=context;
    this.links=links;
}
public View getView(int position, View view, ViewGroup parent){
    LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView=inflater.inflate(R.layout.link,null,true);


TextView textview=(TextView)rowView.findViewById(R.id.textview);
textview.setText(links[position]);
textview.setMovementMethod(LinkMovementMethod.getInstance());
return rowView;}}

I have kept separate xml file for both listview and textview Xml file,

<ListView
    android:id="@+id/useHistoryList"           
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:divider="#ff505050"
    android:background="#ff202020"
    android:dividerHeight="1dp"
    android:transcriptMode="alwaysScroll"
/>

links.xml file,

<TextView

    android:id="@+id/TextView1"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:autoLink="web"
    >
</TextView>
  • Check this post [Custom Adapter for ListView with ArrayList](http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – Rana Shahzaib Feb 13 '17 at 15:41
  • 2
    Possible duplicate of [Custom Adapter for List View](http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – zanussi Feb 13 '17 at 17:13
  • Hi Rana, Here I didnt change my code to custom adapter.. As to my code how should I replace basic adapter with custom adapter to get the messages dynamically into custom adapter. – Pavithra M Feb 14 '17 at 16:16
  • I want to replace basic adapter into custom adapter, so how can I write code to make changes in basic adapter as custom adapter. – Pavithra M Feb 15 '17 at 07:52

0 Answers0