添加了自定义适配单选按钮
This commit is contained in:
@@ -5,20 +5,24 @@ import android.widget.ListView;
|
|||||||
import com.kejiang.yuandl.adapter.common.ViewHolder;
|
import com.kejiang.yuandl.adapter.common.ViewHolder;
|
||||||
import com.kejiang.yuandl.adapter.common.abslistview.CommonAdapter;
|
import com.kejiang.yuandl.adapter.common.abslistview.CommonAdapter;
|
||||||
import com.kejiang.yuandl.base.BaseActivity;
|
import com.kejiang.yuandl.base.BaseActivity;
|
||||||
|
import com.kejiang.yuandl.view.RatingBar;
|
||||||
import com.ldd.pullview.AbPullToRefreshView;
|
import com.ldd.pullview.AbPullToRefreshView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
|
private RatingBar rb;
|
||||||
private AbPullToRefreshView pr;
|
private AbPullToRefreshView pr;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
|
|
||||||
private void assignViews() {
|
private void assignViews() {
|
||||||
|
rb = (RatingBar) findViewById(R.id.rb);
|
||||||
pr = (AbPullToRefreshView) findViewById(R.id.pr);
|
pr = (AbPullToRefreshView) findViewById(R.id.pr);
|
||||||
listView = (ListView) findViewById(R.id.listView);
|
listView = (ListView) findViewById(R.id.listView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initTitleBar() {
|
public void initTitleBar() {
|
||||||
setTitle("试试");
|
setTitle("试试");
|
||||||
@@ -33,6 +37,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initData() {
|
public void initData() {
|
||||||
|
rb.setStar(4.5f);
|
||||||
List<String> datas=new ArrayList<>();
|
List<String> datas=new ArrayList<>();
|
||||||
listView.setAdapter(new CommonAdapter<String>(context,R.layout.item_text,datas){
|
listView.setAdapter(new CommonAdapter<String>(context,R.layout.item_text,datas){
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -7,10 +8,25 @@
|
|||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
android:paddingTop="@dimen/activity_vertical_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
|
<com.ldd.pullview.AbPullToRefreshView
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:id="@+id/pr"
|
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
|
<ListView
|
||||||
android:id="@+id/listView"
|
android:id="@+id/listView"
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/res/mipmap-xhdpi/star_half_yellow.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/star_half_yellow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/star_yellow.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/star_yellow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -5,7 +5,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.kejiang.yuandl.adapter;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.RadioGroup.OnCheckedChangeListener;
|
import android.widget.RadioGroup.OnCheckedChangeListener;
|
||||||
|
|
||||||
@@ -40,35 +41,54 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isLogin = true;
|
||||||
|
|
||||||
|
public void setLogin(boolean isLogin) {
|
||||||
|
this.isLogin = isLogin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
|
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
|
||||||
for (int i = 0; i < rg.getChildCount(); i++) {
|
if(!isLogin){
|
||||||
if (rg.getChildAt(i).getId() == checkedId) {
|
((RadioButton)radioGroup.getChildAt(0)).setChecked(true);
|
||||||
Fragment fragment = fragments.get(i);
|
// 如果设置了切换tab额外功能功能接口
|
||||||
FragmentTransaction ft = obtainFragmentTransaction(i);
|
if (null != onRgsExtraCheckedChangedListener) {
|
||||||
// getCurrentFragment().onPause(); // 暂停当前tab
|
onRgsExtraCheckedChangedListener.needLogin();
|
||||||
//getCurrentFragment().onStop(); // 暂停当前tab
|
|
||||||
|
|
||||||
if (fragment.isAdded()) {
|
|
||||||
// fragment.onStart(); // 启动目标tab的onStart()
|
|
||||||
currentTab = i;
|
|
||||||
if (!fragment.isResumed()) {
|
|
||||||
|
|
||||||
fragment.onResume(); // 启动目标tab的onResume()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ft.add(fragmentContentId, fragment);
|
|
||||||
}
|
|
||||||
showTab(i); // 显示目标tab
|
|
||||||
ft. commitAllowingStateLoss();
|
|
||||||
|
|
||||||
// 如果设置了切换tab额外功能功能接口
|
|
||||||
if (null != onRgsExtraCheckedChangedListener) {
|
|
||||||
onRgsExtraCheckedChangedListener.OnRgsExtraCheckedChanged(
|
|
||||||
radioGroup, checkedId, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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().onStop(); // 暂停当前tab
|
||||||
|
|
||||||
|
if (fragment.isAdded()) {
|
||||||
|
// fragment.onStart(); // 启动目标tab的onStart()
|
||||||
|
currentTab = i;
|
||||||
|
if (!fragment.isResumed()) {
|
||||||
|
|
||||||
|
fragment.onResume(); // 启动目标tab的onResume()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ft.add(fragmentContentId, fragment);
|
||||||
|
}
|
||||||
|
showTab(i); // 显示目标tab
|
||||||
|
ft.commitAllowingStateLoss();
|
||||||
|
|
||||||
|
// 如果设置了切换tab额外功能功能接口
|
||||||
|
if (null != onRgsExtraCheckedChangedListener) {
|
||||||
|
onRgsExtraCheckedChangedListener.OnRgsExtraCheckedChanged(
|
||||||
|
radioGroup, checkedId, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -127,6 +147,9 @@ public class FragmentTabAdapter implements OnCheckedChangeListener {
|
|||||||
* 切换tab额外功能功能接口
|
* 切换tab额外功能功能接口
|
||||||
*/
|
*/
|
||||||
public static class OnRgsExtraCheckedChangedListener {
|
public static class OnRgsExtraCheckedChangedListener {
|
||||||
|
public void needLogin(){
|
||||||
|
|
||||||
|
}
|
||||||
public void OnRgsExtraCheckedChanged(RadioGroup radioGroup,
|
public void OnRgsExtraCheckedChanged(RadioGroup radioGroup,
|
||||||
int checkedId, int index) {
|
int checkedId, int index) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user