activity_main.XML
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- The main content view -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
// Here can Put main layout //
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/white"
android:dividerHeight="2dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="@drawable/round_listview"/>
</android.support.v4.widget.DrawerLayout>
===============================================================
list_single.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:id="@+id/txt"
android:gravity="center"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="18sp"
android:text="haii"
android:paddingLeft="20dp"
android:layout_width="fill_parent"
android:layout_height="50dp" />
</TableRow>
</TableLayout>
================================================
CustomList.java (custom class for listview)
package customListview;
import com.csquare.sfa.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context,
String[] web, Integer[] imageId) {
super(context, R.layout.list_single, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
======================================================================
MainActivity.java
// Before oncreate Method
ListView list; String[] web = { "Leave Feature", "Last Visit Report", "Windows", "Bing", "Wordpress", "Drupal" } ; Integer[] imageId = { R.drawable.ico_leave, R.drawable.ico_lastvisit, R.drawable.app_icon, R.drawable.app_icon, R.drawable.app_icon, R.drawable.app_icon };
// Inside oncreate
CustomList adapter = new CustomList(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.left_drawer);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + position, Toast.LENGTH_LONG)
.show();
if(position==0){
Intent intent = new Intent(getApplicationContext(), Onother_Activity.class);startActivity(intent);
}else if(position==1){
Intent intent = new Intent(getApplicationContext(), Onother_Activity.class);
startActivity(intent);
}
}
});
No comments:
Post a Comment