Screenshot of the activity>请参阅我在下面发布的图片 我想将不同的值传递给我的DramaFragment,但是在将资源放入字符串之后,它们无法被解析,并且在logcat中也没有显示此类错误 标题是关于项目活动的陈词滥调,但不是整个背景即将到来
package com.android.msahakyan.expandablenavigationdrawer;
import android.content.ContentValues;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
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.Button;
import android.widget.EditText;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.Spinner;
import android.widget.Toast;
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.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_musical,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;
}
}
}
<resources>
<string name="app_name">WebTechniQ</string>
<string name="action_settings">Settings</string>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="option">Choose An Option</string>
<string name="greeting">hola !</string>
<string name="name">Vaibhav</string>
<string name="selected_item">Selected item</string>
<string name="select_service">Select Service</string>
<string name="your_budget">Your Budget</string>
<string name="time_frame">Time Frame</string>
<string-array name="select_service_1">
<item>Banner Designing</item>
<item>Blog Marketing</item>
<item>Bulk Email</item>
<item>Bulk SMS</item>
<item>Branding</item>
<item>Brochure Designing</item>
<item>CRM Software</item>
<item>Content Marketing</item>
<item>Domain Registration</item>
<item>Email Marketing</item>
<item>Google Adsence</item>
<item>Graphic Design</item>
<item>Internet Marketing</item>
<item>Logo Design</item>
<item>MLM Software</item>
<item>Pay Per Click(Google Adward)</item>
<item>Product Design</item>
<item>Search Engine Marketing</item>
<item>Search Media Optimization</item>
<item>Search Media Marketing</item>
<item>Server Hosting</item>
<item>Software Development</item>
<item>Template design</item>
<item>Visiting card</item>
</string-array>
<string-array name="your_budget_1">
<item>Less than 5,000</item>
<item>5,000-10,000</item>
<item>10,000-25,000</item>
<item>25,000-50,000</item>
<item>50,000</item>
</string-array>
<string-array name="time_frame_1">
<item>1 day</item>
<item>Less than a week</item>
<item>less than 15 days</item>
<item>A month</item>
<item>As per Company Time Frame</item>
</string-array>
<string-array name="choose">
<item>Home</item>
<item>Who we Are</item>
<item>Services</item>
<item>Online Marketing</item>
<item>Contact</item>
</string-array>
<string-array name="home_1">
<item>Home</item>
</string-array>
<string-array name="who_1">
</string-array>
<string-array name="service_1">
<item>Website Design</item>
<item>Web Application</item>
<item>Graphic Design</item>
<item>Website Redisigning</item>
<item>Software Development</item>
<item>Apps Development</item>
<item>Digital Marketing</item>
<item>Domain Registration</item>
<item>Server Hosting</item>
<item>Web Security(SSL)</item>
</string-array>
<string-array name="online_1">
<item>Search Engine Optimization (SEO)</item>
<item>Search Engine Marketing (SEM) </item>
<item>Social Media Optimization (SMO) </item>
<item>Social Media Marketing (SMM) </item>
<item>Email marketing </item>
<item>Pay Per Click (PPC) </item>
<item>Blog Marketing </item>
<item>Branding</item>
<item>Bulk E-mail</item>
<item>Bulk SMS</item>
<item>Content Marketing </item>
<item>Marketing Packages)</item>
</string-array>
<string-array name="contact_1">
</string-array>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="content">this is blah blah</string>
<string name="home">Home</string>
<string name="contact">contact</string>
<string name="services">Services</string>
<string name="who">Who We Are</string>
<string name="online">Online Marketing</string>
<string name="query">Query Form</string>
<string name="Website_Design">
India is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landmarks include Delhi\’s Red Fort complex and massive Jama Masjid mosque, plus Agra’s iconic Taj Mahal mausoleum.
Pilgrims bathe in the Ganges in Varanasi, and Rishikesh is a yoga centre and base for Himalayan trekking.
</string>
<string name="Web_Application" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm</string>
<string name="Graphic_Design" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Website_Redisigning" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Software_Development" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Apps_Development" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Digital_Marketing" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Domain_Registration" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Server_Hosting" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
<string name="Web_Security" >
is a vast South Asian country with diverse terrain – from Himalayan peaks to Indian Ocean coastline – and history reaching back 5 millennia.
In the north, Mughal Empire landm
</string>
</resources>