public class Main2Activity extends AppCompatActivity {
private RadioGroup group;
private ListView listView;
private String path="http://120.27.23.105/product/getCatagory";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main2 );
group = findViewById( R.id.rg );
listView = findViewById( R.id.lv );
initData();
listView.setOnItemClickListener( new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent( Main2Activity.this, Main3Activity.class );
startActivity( intent );
}
} );
getSupportFragmentManager().beginTransaction().replace( R.id.fcontent,new Fragment02() ).commit();
group.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.but1:
getSupportFragmentManager().beginTransaction().replace( R.id.fcontent,new Fragment01() ).commit();
break;
case R.id.but2:
getSupportFragmentManager().beginTransaction().replace( R.id.fcontent,new Fragment02() ).commit();
break;
case R.id.but3:
getSupportFragmentManager().beginTransaction().replace( R.id.fcontent,new Fragment03() ).commit();
break;
case R.id.but4:
getSupportFragmentManager().beginTransaction().replace( R.id.fcontent,new Fragment04() ).commit();
break;
}
}
} );
}
private void initData() {
MyTask task = new MyTask(new MyTask.ICallBacks() {
@Override
public void getJsonData(String jsonstr) {
Gson gson = new Gson();
ReaData2 reaData2 = gson.fromJson( jsonstr, ReaData2.class );
List<ReaData2.DataBean> data = reaData2.getData();
MyAdapter2 myAdapter2 = new MyAdapter2( data, Main2Activity.this );
listView.setAdapter( myAdapter2 );
}
} );
task.execute( path );
}
}
public class MyAdapter2 extends BaseAdapter {
List<ReaData2.DataBean> list;
Context context;
private final DisplayImageOptions options;
public MyAdapter2(List<ReaData2.DataBean> list, Context context) {
this.list = list;
this.context = context;
//使用内存缓存
//使用磁盘缓存
//设置图片色彩模式
//设置图片的缩放模式
// .displayer(new RoundedBitmapDisplayer(50))//设置圆角
options = new DisplayImageOptions.Builder().cacheInMemory( true )//使用内存缓存
.cacheOnDisk( true )//使用磁盘缓存
.bitmapConfig( Bitmap.Config.RGB_565 )//设置图片色彩模式
.imageScaleType( ImageScaleType.EXACTLY )//设置图片的缩放模式
// .displayer(new RoundedBitmapDisplayer(50))//设置圆角
.build();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get( position );
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MyHolder myHolder;
if (convertView==null){
convertView=View.inflate( context, R.layout.main2,null );
myHolder = new MyHolder();
myHolder.textView=convertView.findViewById( R.id.tv );
myHolder.imageView=convertView.findViewById( R.id.img );
convertView.setTag( myHolder );
}else {
myHolder= (MyHolder) convertView.getTag();
}
myHolder.textView.setText( list.get( position ).getName() );
ImageLoader.getInstance().displayImage( list.get( position ).getIcon(),myHolder.imageView,options );
return convertView;
}
class MyHolder{
TextView textView;
ImageView imageView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:id="@+id/rg">
<RadioButton
android:layout_width="0dp"
android:layout_height="56dp"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:background="@drawable/selector_home"
android:id="@+id/but1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="56dp"
android:background="@drawable/selector_find"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:id="@+id/but2"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="56dp"
android:button="@null"
android:background="@drawable/selector_shop"
android:layout_weight="1"
android:gravity="center"
android:id="@+id/but3"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="56dp"
android:background="@drawable/selector_mine"
android:button="@null"
android:layout_weight="1"
android:gravity="center"
android:id="@+id/but4"/>
</RadioGroup>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fcontent"
android:layout_above="@id/rg"
>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#aff"
>
<ImageView
android:layout_width="1800dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:src="@drawable/a6"
android:id="@+id/iii"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lv"
android:layout_below="@id/iii"></ListView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>