在下面的代码中,我想为我的孩子戏剧中提供不同的值,即服务,设计等,但是在解析不同的值并在XML文件中声明它也显示错误我不知道为什么。
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;
}
}
}
<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>
<!-- 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>
[1]:https://i.stack.imgur.com/01PGt.png这是在logcat中弹出的错误