android中不同ExpandAvable listview中的相同值
可扩展列表视图图像 我面临的错误 相同的内容和图像视图 正如你可以看到上面的图片,我想给我不同的expandablelistview添加不同的值 我面临的问题是,它在每个选择的可扩展视图选项中显示相同的内容 main活动android中不同ExpandAvable listview中的相同值,android,listview,android-fragments,expandablelistview,Android,Listview,Android Fragments,Expandablelistview,可扩展列表视图图像 我面临的错误 相同的内容和图像视图 正如你可以看到上面的图片,我想给我不同的expandablelistview添加不同的值 我面临的问题是,它在每个选择的可扩展视图选项中显示相同的内容 main活动 package com.android.msahakyan.expandablenavigationdrawer; import android.content.res.Configuration; import android.os.Bundle;
package com.android.msahakyan.expandablenavigationdrawer;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import com.android.msahakyan.expandablenavigationdrawer.adapter.CustomExpandableListAdapter;
import com.android.msahakyan.expandablenavigationdrawer.datasource.ExpandableListDataSource;
import com.android.msahakyan.expandablenavigationdrawer.fragment.navigation.FragmentNavigationManager;
import com.android.msahakyan.expandablenavigationdrawer.fragment.navigation.NavigationManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
String selectedOption;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private String mActivityTitle;
private String[] items;
private ExpandableListView mExpandableListView;
private ExpandableListAdapter mExpandableListAdapter;
private List<String> mExpandableListTitle;
private NavigationManager mNavigationManager;
private Map<String, List<String>> mExpandableListData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
mExpandableListView = (ExpandableListView) findViewById(R.id.navList);
mNavigationManager = FragmentNavigationManager.obtain(this);
initItems();
LayoutInflater inflater = getLayoutInflater();
View listHeaderView = inflater.inflate(R.layout.nav_header, null, false);
mExpandableListView.addHeaderView(listHeaderView);
mExpandableListData = ExpandableListDataSource.getData(this);
mExpandableListTitle = new ArrayList(mExpandableListData.keySet());
addDrawerItems();
setupDrawer();
if (savedInstanceState == null) {
selectFirstItemAsDefault();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
private void selectFirstItemAsDefault() {
if (mNavigationManager != null) {
String firstActionMovie = getResources().getStringArray(R.array.home_1)[0];
mNavigationManager.showFragmentAction(firstActionMovie);
getSupportActionBar().setTitle(firstActionMovie);
}
}
private void initItems() {
items = getResources().getStringArray(R.array.choose);
}
private void addDrawerItems() {
mExpandableListAdapter = new CustomExpandableListAdapter(this, mExpandableListTitle, mExpandableListData);
mExpandableListView.setAdapter(mExpandableListAdapter);
mExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
getSupportActionBar().setTitle(mExpandableListTitle.get(groupPosition).toString());
}
});
mExpandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
getSupportActionBar().setTitle(R.string.option);
}
});
mExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
String selectedItem = ((List) (mExpandableListData.get(mExpandableListTitle.get(groupPosition))))
.get(childPosition).toString();
getSupportActionBar().setTitle(selectedItem);
if (items[0].equals(mExpandableListTitle.get(groupPosition))) {
mNavigationManager.showFragmentAction(selectedItem);
} else if (items[1].equals(mExpandableListTitle.get(groupPosition))) {
mNavigationManager.showFragmentComedy(selectedItem);
} else if (items[2].equals(mExpandableListTitle.get(groupPosition))) {
mNavigationManager.showFragmentDrama(selectedItem);
} else if (items[3].equals(mExpandableListTitle.get(groupPosition))) {
mNavigationManager.showFragmentMusical(selectedItem);
} else if (items[4].equals(mExpandableListTitle.get(groupPosition))) {
mNavigationManager.showFragmentThriller(selectedItem);
} else {
throw new IllegalArgumentException("Not supported fragment type");
}
mDrawerLayout.closeDrawer(GravityCompat.START);
return false;
}
});
}
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(R.string.option);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
package com.android.msahakyan.expandablenavigationdrawer;
导入android.content.res.Configuration;
导入android.os.Bundle;
导入android.support.v4.view.GravityCompat;
导入android.support.v4.widget.DrawerLayout;
导入android.support.v7.app.ActionBarDrawerToggle;
导入android.support.v7.app.AppActivity;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.ExpandableListAdapter;
导入android.widget.ExpandableListView;
导入com.android.msahakyan.expandablenavigationdrawer.adapter.CustomExpandableListAdapter;
导入com.android.msahakyan.expandablenavigationdrawer.datasource.ExpandableListDataSource;
导入com.android.msahakyan.expandablenavigationdrawer.fragment.navigation.FragmentNavigationManager;
导入com.android.msahakyan.expandablenavigationdrawer.fragment.navigation.NavigationManager;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Map;
公共类MainActivity扩展了AppCompatActivity{
字符串选择选项;
私人抽屉布局mDrawerLayout;
私有操作bardrawertoggle mDrawerToggle;
私有字符串mactivitytle;
私有字符串[]项;
私有可扩展列表视图mExpandableListView;
私有可扩展列表适配器mExpandableListAdapter;
私有列表mExpandableListTitle;
私人导航经理mNavigationManager;
私有地图mExpandableListData;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mActivityTitle=getTitle().toString();
mExpandableListView=(ExpandableListView)findViewById(R.id.navList);
mNavigationManager=FragmentNavigationManager.get(此);
initItems();
LayoutInflater充气机=getLayoutInflater();
视图listHeaderView=充气机。充气(R.layout.nav_标题,空,假);
mExpandableListView.addHeaderView(listHeaderView);
mExpandableListData=ExpandableListDataSource.getData(这个);
mExpandableListTitle=新的ArrayList(mExpandableListData.keySet());
addDrawerItems();
setupDrawer();
如果(savedInstanceState==null){
选择FirstItemasDefault();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
私有void selectFirstItemAsDefault(){
if(mNavigationManager!=null){
String firstActionMovie=getResources().getStringArray(R.array.home_1)[0];
mNavigationManager.showFragmentAction(firstActionMovie);
getSupportActionBar().setTitle(firstActionMovie);
}
}
私有项目(){
items=getResources().getStringArray(R.array.choose);
}
私有void addDrawerItems(){
mExpandableListAdapter=新的CustomExpandableListAdapter(此,mExpandableListTitle,mExpandableListData);
setAdapter(mExpandableListAdapter);
mExpandableListView.setOnGroupExpandListener(新的ExpandableListView.OnGroupExpandListener(){
@凌驾
public void onGroupExpand(int groupPosition){
getSupportActionBar().setTitle(mExpandableListTitle.get(groupPosition.toString());
}
});
mExpandableListView.setOnGroupCollapseListener(新的ExpandableListView.OnGroupCollapseListener(){
@凌驾
公共void-onGroupCollapse(int-groupPosition){
getSupportActionBar().setTitle(R.string.option);
}
});
mExpandableListView.setOnChildClickListener(新的ExpandableListView.OnChildClickListener(){
@凌驾
公共布尔onChildClick(ExpandableListView父视图,视图v,
int groupPosition、int childPosition、long id){
字符串selectedItem=((列表)(mExpandableListData.get(mExpandableListTitle.get(groupPosition)))
.get(childPosition.toString();
getSupportActionBar().setTitle(selectedItem);
if(items[0].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentAction(selectedItem);
}else if(items[1].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentComicle(selectedItem);
}else if(items[2].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragment戏剧性(selectedItem);
}else if(items[3].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentMusic(selectedItem);
}else if(items[4].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentThriller(selectedItem);
}否则{
抛出新的IllegalArgumentException(“不支持的片段类型”);
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import com.android.msahakyan.expandablenavigationdrawer.R;
import java.util.List;
import java.util.Map;
public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private List<String> mExpandableListTitle;
private Map<String, List<String>> mExpandableListDetail;
private LayoutInflater mLayoutInflater;
public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
Map<String, List<String>> expandableListDetail) {
mContext = context;
mExpandableListTitle = expandableListTitle;
mExpandableListDetail = expandableListDetail;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public Object getChild(int listPosition, int expandedListPosition) {
return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
.get(expandedListPosition);
}
@Override
public long getChildId(int listPosition, int expandedListPosition) {
return expandedListPosition;
}
@Override
public View getChildView(int listPosition, final int expandedListPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String expandedListText = (String) getChild(listPosition, expandedListPosition);
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.list_item, null);
}
TextView expandedListTextView = (TextView) convertView
.findViewById(R.id.expandedListItem);
expandedListTextView.setText(expandedListText);
return convertView;
}
@Override
public int getChildrenCount(int listPosition) {
return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
.size();
}
@Override
public Object getGroup(int listPosition) {
return mExpandableListTitle.get(listPosition);
}
@Override
public int getGroupCount() {
return mExpandableListTitle.size();
}
@Override
public long getGroupId(int listPosition) {
return listPosition;
}
@Override
public View getGroupView(int listPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String listTitle = (String) getGroup(listPosition);
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.list_group, null);
}
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.listTitle);
listTitleTextView.setTypeface(null, Typeface.BOLD);
listTitleTextView.setText(listTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) {
return true;
}
}
package com.android.msahakyan.expandablenavigationdrawer.fragment;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.msahakyan.expandablenavigationdrawer.R;
import com.android.msahakyan.expandablenavigationdrawer.Registration;
import com.android.msahakyan.expandablenavigationdrawer.fragment.navigation.FragmentActionListener;
/**
* A simple {@link Fragment} subclass.
* Use the {@link FragmentDrama#newInstance} factory method to
* create an instance of this fragment.
*/
public class FragmentDrama extends Fragment {
private static final String KEY_MOVIE_TITLE = "key_title";
String movieName;
String movieDescription;
public FragmentDrama() {
// Required empty public constructor
}
public static FragmentDrama newInstance(String movieTitle) {
FragmentDrama fragmentDrama = new FragmentDrama();
Bundle args = new Bundle();
args.putString(KEY_MOVIE_TITLE, movieTitle);
fragmentDrama.setArguments(args);
return fragmentDrama;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_drama,container,false);
ImageButton imageButton =(ImageButton)v.findViewById(R.id.movie_icon);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity( new Intent( getActivity(), Registration.class ) );
}
});
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Drawable movieIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.webdesign, getContext().getTheme());
// if (movieIcon != null) {
// movieIcon.setColorFilter(ContextCompat.getColor(getContext(), R.color.grey), PorterDuff.Mode.SRC_ATOP);
//}
((ImageButton) view.findViewById(R.id.movie_icon)).setImageDrawable(movieIcon);
String movieTitle = getArguments().getString(KEY_MOVIE_TITLE);
((TextView) view.findViewById(R.id.movie_title)).setText(movieTitle);
}
/* @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated( savedInstanceState );
if(savedInstanceState!=null){
movieName = savedInstanceState.getString("selectedMovie",movieName);
movieDescription = getString(getStringId(movieName));
}else {
Bundle bundle = getArguments();
movieName = bundle.getString( FragmentActionListener.KEY_SELECTED_MOVIE,"Website Design");
movieDescription = getString(getStringId(movieName));
}
}
private int getStringId(String movieName){
if(movieName.equals("Website Design")){
return R.string.Website_Design;
}else if(movieName.equals("Web Application")){
return R.string.Web_Application;
}else if(movieName.equals("Graphic Design")){
return R.string.Graphic_Design;
}else if(movieName.equals("Website Redisigning")){
return R.string.Website_Redisigning;
}else if(movieName.equals("Software Development")){
return R.string.Software_Development;
}else if(movieName.equals("Apps Development")){
return R.string.Apps_Development;
}else if(movieName.equals("Digital Marketing")){
return R.string.Digital_Marketing;
}else if(movieName.equals("Domain Registration")) {
return R.string.Domain_Registration;
}else if(movieName.equals("Server Hosting")) {
return R.string.Server_Hosting;
}else if(movieName.equals("Web Security(SSL)")){
return R.string.Web_Security;
}else {
return R.string.Website_Design;
}
}*/
}
#drama_fragment.xml
[<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.msahakyan.expandablenavigationdrawer.fragment.FragmentDrama">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/movie_icon_container_height">
<ImageButton
android:id="@+id/movie_icon"
android:layout_width="match_parent"
android:layout_height="150dp"
android:contentDescription="@string/query"
android:src="@drawable/webdesign" />
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:gravity="center"-->
<!--android:padding="@dimen/layout_padding_default"-->
<!--android:text="@string/services"-->
<!--android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"-->
<!--android:textColor="@color/white"/>-->
</FrameLayout>
<TextView
android:id="@+id/movie_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="@dimen/layout_padding_default"
android:text="@string/content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="adsjxknxlanm,a"
android:textSize="20dp"/>
</ScrollView>
</LinearLayout>]
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String movieTitle = getArguments().getString(KEY_MOVIE_TITLE);
((TextView) view.findViewById(R.id.movie_title)).setText(movieTitle);
String imagekey = getArguments().getString(KEY_FOR_IMAGE);
String content= getArguments().getString(KEY_CONTENT);
if (imagekey = "movie"){
Drawable movieIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.webdesign, getContext().getTheme());
// if (movieIcon != null) {
// movieIcon.setColorFilter(ContextCompat.getColor(getContext(), R.color.grey), PorterDuff.Mode.SRC_ATOP);
//}
((ImageButton) view.findViewById(R.id.movie_icon)).setImageDrawable(movieIcon);
}else if(){
so on . . .
}
((TextView) view.findViewById(R.id.content)).setText(content);
}
in fragemt you are only changing title ;
and image is same and not setting content .
pass content and imagekey to choose which image to show along with title