CustomToast_gujinfo
//Custom_Toast ie whatsup jevu page
1>MainActivity.xml
2>second.xml & java
3>mylist.xml
4>MainActivity.java
5>Adapter.java
6>pojo.java
7>second.java
step 1:MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="demoproject.aalap.com.custom_listview.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list">
</ListView>
</RelativeLayout>
Step 2:second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demoproject.aalap.com.custom_listview.second">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv11"
android:textSize="20sp"/>
</LinearLayout>
Step 3:mylist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"/>
</LinearLayout>
</LinearLayout>
Step 4:mainActivity.java
package demoproject.aalap.com.custom_listview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ListView list;
ArrayList<pojo> ar;
String[] maintitle ={
"Title 1","Title 2",
"Title 3","Title 4",
"Title 5",
};
String[] subtitle ={
"Sub Title 1","Sub Title 2",
"Sub Title 3","Sub Title 4",
"Sub Title 5",
};
Integer[] imgid={
R.drawable.ic_tag_faces_black_24dp,R.drawable.ic_tag_faces_black_24dp,
R.drawable.ic_tag_faces_black_24dp,R.drawable.ic_tag_faces_black_24dp,
R.drawable.ic_tag_faces_black_24dp,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ar=new ArrayList<>();
for(int i=0;i<maintitle.length;i++){
pojo p=new pojo();
p.setMaintitle(maintitle[i]);
p.setSubtitle(subtitle[i]);
p.setImageid(imgid[i]);
ar.add(p);
}
Adapter adapter=new Adapter(this, ar);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(MainActivity.this,second.class);
intent.putExtra("username",ar.get(i).getMaintitle());
startActivity(intent);
}
});
}
}
Step 5:Adapter.java
package demoproject.aalap.com.custom_listview;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by ADMIN on 23-07-2018.
*/
public class Adapter extends BaseAdapter {
Activity mainActivity;
ArrayList<pojo> ar;
public Adapter(Activity mainActivity, ArrayList<pojo> ar) {
this.ar=ar;
this.mainActivity=mainActivity;
}
@Override
public int getCount() {
return ar.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view=mainActivity.getLayoutInflater().inflate(R.layout.mylist,viewGroup,false);
TextView mytitle=view.findViewById(R.id.title);
TextView sub=view.findViewById(R.id.subtitle);
ImageView icon=view.findViewById(R.id.icon);
pojo p=ar.get(i);
mytitle.setText(p.getMaintitle());
sub.setText(p.getSubtitle());
icon.setImageResource(p.getImageid());
return view;
}
}
Step 6:pojo.java
package demoproject.aalap.com.custom_listview;
/**
* Created by ADMIN on 23-07-2018.
*/
public class pojo {
String maintitle,subtitle;
int imageid;
public String getMaintitle() {
return maintitle;
}
public void setMaintitle(String maintitle) {
this.maintitle = maintitle;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public int getImageid() {
return imageid;
}
public void setImageid(int imageid) {
this.imageid = imageid;
}
}
Step 7:Second.java
package demoproject.aalap.com.custom_listview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class second extends AppCompatActivity {
TextView tv11;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tv11=findViewById(R.id.tv11);
String data = getIntent().getExtras().getString("username");
tv11.setText(data);
}
}
1>MainActivity.xml
2>second.xml & java
3>mylist.xml
4>MainActivity.java
5>Adapter.java
6>pojo.java
7>second.java
step 1:MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="demoproject.aalap.com.custom_listview.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list">
</ListView>
</RelativeLayout>
Step 2:second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demoproject.aalap.com.custom_listview.second">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv11"
android:textSize="20sp"/>
</LinearLayout>
Step 3:mylist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"/>
</LinearLayout>
</LinearLayout>
Step 4:mainActivity.java
package demoproject.aalap.com.custom_listview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ListView list;
ArrayList<pojo> ar;
String[] maintitle ={
"Title 1","Title 2",
"Title 3","Title 4",
"Title 5",
};
String[] subtitle ={
"Sub Title 1","Sub Title 2",
"Sub Title 3","Sub Title 4",
"Sub Title 5",
};
Integer[] imgid={
R.drawable.ic_tag_faces_black_24dp,R.drawable.ic_tag_faces_black_24dp,
R.drawable.ic_tag_faces_black_24dp,R.drawable.ic_tag_faces_black_24dp,
R.drawable.ic_tag_faces_black_24dp,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ar=new ArrayList<>();
for(int i=0;i<maintitle.length;i++){
pojo p=new pojo();
p.setMaintitle(maintitle[i]);
p.setSubtitle(subtitle[i]);
p.setImageid(imgid[i]);
ar.add(p);
}
Adapter adapter=new Adapter(this, ar);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(MainActivity.this,second.class);
intent.putExtra("username",ar.get(i).getMaintitle());
startActivity(intent);
}
});
}
}
Step 5:Adapter.java
package demoproject.aalap.com.custom_listview;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by ADMIN on 23-07-2018.
*/
public class Adapter extends BaseAdapter {
Activity mainActivity;
ArrayList<pojo> ar;
public Adapter(Activity mainActivity, ArrayList<pojo> ar) {
this.ar=ar;
this.mainActivity=mainActivity;
}
@Override
public int getCount() {
return ar.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view=mainActivity.getLayoutInflater().inflate(R.layout.mylist,viewGroup,false);
TextView mytitle=view.findViewById(R.id.title);
TextView sub=view.findViewById(R.id.subtitle);
ImageView icon=view.findViewById(R.id.icon);
pojo p=ar.get(i);
mytitle.setText(p.getMaintitle());
sub.setText(p.getSubtitle());
icon.setImageResource(p.getImageid());
return view;
}
}
Step 6:pojo.java
package demoproject.aalap.com.custom_listview;
/**
* Created by ADMIN on 23-07-2018.
*/
public class pojo {
String maintitle,subtitle;
int imageid;
public String getMaintitle() {
return maintitle;
}
public void setMaintitle(String maintitle) {
this.maintitle = maintitle;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public int getImageid() {
return imageid;
}
public void setImageid(int imageid) {
this.imageid = imageid;
}
}
Step 7:Second.java
package demoproject.aalap.com.custom_listview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class second extends AppCompatActivity {
TextView tv11;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tv11=findViewById(R.id.tv11);
String data = getIntent().getExtras().getString("username");
tv11.setText(data);
}
}
Comments
Post a Comment