Main2Activity界面主页设置
Posted xiaxinxin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Main2Activity界面主页设置相关的知识,希望对你有一定的参考价值。
public class Main2Activity extends AppCompatActivity {
private ListView lv;
private RadioGroup rg;
private FrameLayout fl;
private String murl="http://api.tianapi.com/huabian/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
lv = findViewById(R.id.lv);
rg = findViewById(R.id.rg);
fl = findViewById(R.id.fl);
getSupportFragmentManager().beginTransaction().replace(R.id.fl,new Fragment01()).commit();
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.but1:
getSupportFragmentManager().beginTransaction().replace(R.id.fl,new Fragment01()).commit();break;
case R.id.but2:
getSupportFragmentManager().beginTransaction().replace(R.id.fl,new Fragment02()).commit();break;
case R.id.but3:
getSupportFragmentManager().beginTransaction().replace(R.id.fl,new Fragment03()).commit();break;
case R.id.but4:
getSupportFragmentManager().beginTransaction().replace(R.id.fl,new Fragment04()).commit();break;
}
}
});
lv.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);
Toast.makeText(Main2Activity.this,"hhhhhhh",Toast.LENGTH_SHORT).show();
}
});
}
private void getdata(){
MyTask myTask=new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Gson gson=new Gson();
Result result = gson.fromJson(jsonstr, Result.class);
List<Result.NewslistBean> newslist =result.getNewslist();
MyAdapter myAdapter=new MyAdapter(newslist,Main2Activity.this);
lv.setAdapter(myAdapter);
}
});
myTask.execute(murl);
}
public void tiao(View view){
Intent intent1=new Intent(Main2Activity.this,Main3Activity.class);
startActivity(intent1);
}
}
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dl">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9.1"
android:id="@+id/fl">
</FrameLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:id="@+id/rg"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/but1"
android:gravity="center"
android:checked="true"
android:drawableBottom="@drawable/select"
android:button="@null"
android:text="首页"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/but2"
android:gravity="center"
android:checked="true"
android:drawableBottom="@drawable/select1"
android:button="@null"
android:text="咨询"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/but3"
android:gravity="center"
android:checked="true"
android:drawableBottom="@drawable/select2"
android:button="@null"
android:text="设置"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/but4"
android:checked="true"
android:gravity="center"
android:onClick="tiao"
android:drawableBottom="@drawable/select3"
android:button="@null"
android:text="我的"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#f00"
android:layout_gravity="start"
>
<ImageView
android:layout_width="180dp"
android:layout_height="180dp"
android:id="@+id/img"
android:background="@mipmap/ic_launcher"/>
<ListView
android:layout_width="match_parent"
android:layout_marginTop="100dp"
android:layout_height="match_parent"
android:id="@+id/lv"></ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
以上是关于Main2Activity界面主页设置的主要内容,如果未能解决你的问题,请参考以下文章