私は主要なプロジェクトに取り組んでおり、取得した文字列配列の値に基づいて別のインテントを開くようにしたい。ボタンのOnClickListener内にif文とelse if文を使用しましたが、もうクリックしません。私を助けてください。ifステートメントをAndroidのボタンのOnClickListener内に配置する方法
これは私のXMLファイルである:私は私の場合、他の条件はの値に基づいて仕事をしたい
public class ActivityBookDetails extends AppCompatActivity {
public static final String EXTRA_OBJCT = "com.app.sample.recipe.OBJ";
private Book book;
private FloatingActionButton fab;
private View parent_view;
Button button;
String[] obj;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_book_details);
parent_view = findViewById(android.R.id.content);
button = (Button)findViewById(R.id.buttonpdf);
book = (Book) getIntent().getSerializableExtra(EXTRA_OBJCT);
fab = (FloatingActionButton) findViewById(R.id.fab);
fabToggle();
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(book.getName());
((ImageView) findViewById(R.id.image)).setImageResource(book.getPhoto());
LinearLayout subjects = (LinearLayout) findViewById(R.id.subjects);
final String[] title_subjects = getResources().getStringArray(R.array.Subjects);
addIngredientsList(subjects, title_subjects);
obj = title_subjects;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ("Soft Computing".equals(obj)) {
Intent intent = new Intent(ActivityBookDetails.this, pdfviewactivity.class);
startActivity(intent);
}
else if ("Web Engineering".equals(obj)) {
Intent intent = new Intent(ActivityBookDetails.this, pdfweben.class);
startActivity(intent);
}
else if ("Network Management".equals(obj)) {
Intent intent = new Intent(ActivityBookDetails.this, pdfnetwork.class);
startActivity(intent);
}
else if ("Wireless Network".equals(obj)) {
Intent intent = new Intent(ActivityBookDetails.this, pdfwireless.class);
startActivity(intent);
}
}
});
:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="3dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/spacing_large">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/spacing_middle"
android:text="Syllabus"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<Button
android:id="@+id/buttonpdf"
style="@style/Widget.AppCompat.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="Open Book" />
</LinearLayout>
そして、これが同じ活動のためのJavaファイルであります文字列配列。 ... ...
if ("Soft Computing".equals(obj)) {
(注
final String[] title_subjects = getResources().getStringArray(R.array.Subjects);
obj = title_subjects;
そして
public class pdfwireless extends AppCompatActivity {
PDFView pdfView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdfwireless);
pdfView = (PDFView)findViewById(R.id.pdfView);
pdfView.fromAsset("wirelessnetwork.pdf").load();
}
}
デバッグし、 'obj'の値を確認してください –