This Project is Android Studio Project Version :1.3.2
this project if Running Problem please Comment Please:
ANDROID STUDIO CUSTOM LIST VIEW PROJECT
Android CustomList View Tutorial
MainActivity
package com.example.faruk.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends AppCompatActivity { ListView listView; String[]item={ "Salma", "Rabia", "Salma", "Rana", "Rabia", "Salma", "Rana", "Rabia", "Salma", "Rana", "Rabia", "Salma"}; Integer []image={ R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk, R.drawable.faruk,}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView= (ListView) findViewById(R.id.list_v); CustomListViewAdapter adapter=new CustomListViewAdapter(this,item,image); listView.setAdapter(adapter); } }
Java Class
CustomListViewAdapter Class
public class CustomListViewAdapter extends ArrayAdapter<String> { final Context context; String []item; Integer []image; public CustomListViewAdapter(Context context,String[]item,Integer[]image) { super(context,R.layout.second,item); this.context=context; this.item=item; this.image=image; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View faruk=inflater.inflate(R.layout.second,parent,false); ImageView imageV=(ImageView) faruk.findViewById(R.id.image_v); TextView title=
(TextView) faruk.findViewById(R.id.text_v_1); TextView rat =
(TextView) faruk.findViewById(R.id.text_v_2); imageV.setImageResource(image[position]); title.setText(item[position]); return faruk; } }Activity Main Xml Code under:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity"> <ListViewandroid:id="@+id/list_v"android:layout_width="match_parent"android:layout_height="match_parent"> </ListView> </RelativeLayout>Second Activity XML Code under:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_marginTop="16dp"android:layout_marginBottom="10dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_height="wrap_content"> <ImageViewandroid:id="@+id/image_v"android:layout_width="90dp"android:layout_height="90dp" /> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center"android:orientation="vertical"> <TextViewandroid:id="@+id/text_v_1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:text="Title"/> <TextViewandroid:id="@+id/text_v_2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Title"/> </LinearLayout> </LinearLayout>Screen Shot List View Under:
0 comments
Post a Comment
Thank you for your comment..................................