添加了自定义适配单选按钮

This commit is contained in:
linglongxin24
2016-06-08 14:08:42 +08:00
parent 06465bac0f
commit ede128d340
7 changed files with 73 additions and 29 deletions

View File

@@ -5,20 +5,24 @@ import android.widget.ListView;
import com.kejiang.yuandl.adapter.common.ViewHolder;
import com.kejiang.yuandl.adapter.common.abslistview.CommonAdapter;
import com.kejiang.yuandl.base.BaseActivity;
import com.kejiang.yuandl.view.RatingBar;
import com.ldd.pullview.AbPullToRefreshView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends BaseActivity {
private RatingBar rb;
private AbPullToRefreshView pr;
private ListView listView;
private void assignViews() {
rb = (RatingBar) findViewById(R.id.rb);
pr = (AbPullToRefreshView) findViewById(R.id.pr);
listView = (ListView) findViewById(R.id.listView);
}
@Override
public void initTitleBar() {
setTitle("试试");
@@ -33,6 +37,7 @@ public class MainActivity extends BaseActivity {
@Override
public void initData() {
rb.setStar(4.5f);
List<String> datas=new ArrayList<>();
listView.setAdapter(new CommonAdapter<String>(context,R.layout.item_text,datas){
@Override

View File

@@ -1,5 +1,6 @@
<?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"
@@ -7,10 +8,25 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<com.kejiang.yuandl.view.RatingBar
android:background="#FFFFFF"
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:starCount="5"
app:starEmpty="@mipmap/star_grey"
app:starFill="@mipmap/star_yellow"
app:starHalf="@mipmap/star_half_yellow"
app:starImageSize="20dp"
app:starStep="4.5"></com.kejiang.yuandl.view.RatingBar>
<com.ldd.pullview.AbPullToRefreshView
android:layout_width="match_parent"
android:id="@+id/pr"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rb">
<ListView
android:id="@+id/listView"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@@ -3,6 +3,7 @@ package com.kejiang.yuandl.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
@@ -40,13 +41,29 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
}
private boolean isLogin = true;
public void setLogin(boolean isLogin) {
this.isLogin = isLogin;
}
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
if(!isLogin){
((RadioButton)radioGroup.getChildAt(0)).setChecked(true);
// 如果设置了切换tab额外功能功能接口
if (null != onRgsExtraCheckedChangedListener) {
onRgsExtraCheckedChangedListener.needLogin();
}
return;
}
try {
for (int i = 0; i < rg.getChildCount(); i++) {
if (rg.getChildAt(i).getId() == checkedId) {
Fragment fragment = fragments.get(i);
FragmentTransaction ft = obtainFragmentTransaction(i);
// getCurrentFragment().onPause(); // 暂停当前tab
// getCurrentFragment().onPause(); // 暂停当前tab
//getCurrentFragment().onStop(); // 暂停当前tab
if (fragment.isAdded()) {
@@ -60,7 +77,7 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
ft.add(fragmentContentId, fragment);
}
showTab(i); // 显示目标tab
ft. commitAllowingStateLoss();
ft.commitAllowingStateLoss();
// 如果设置了切换tab额外功能功能接口
if (null != onRgsExtraCheckedChangedListener) {
@@ -70,6 +87,9 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -127,6 +147,9 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
* 切换tab额外功能功能接口
*/
public static class OnRgsExtraCheckedChangedListener {
public void needLogin(){
}
public void OnRgsExtraCheckedChanged(RadioGroup radioGroup,
int checkedId, int index) {