Расширяемое изображение ListView
Ошибка, с которой я сталкиваюсь
Одинаковое содержимое и просмотр изображений
Как вы можете видеть вышеупомянутые изображения, я хочу добавить различные значения в мой другой расширяемый список просмотра.
Проблема, с которой я сталкиваюсь, заключается в том, что он показывает мне один и тот же контент в каждой выбранной опции расширяемого представления.
MainActivity
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);
}
}
CustomExpandableListAdapter
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;
}
}
FragmentDrama
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>]