码迷,mamicode.com
首页 > 其他好文 > 详细

Main2Activity界面主页设置

时间:2018-05-03 22:11:19      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:checked   ati   api   app   task   long   change   咨询   fragment   

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界面主页设置

标签:checked   ati   api   app   task   long   change   咨询   fragment   

原文地址:https://www.cnblogs.com/xiaxinxin/p/8987323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!