Я пытаюсь отправить целые числа из 7 различных фрагментов в 8-й фрагмент, который будет отправлен в базу данных SQLite.Однако в настоящее время я не могу получить что-либо для отправки в другой фрагмент.
MiscTab.java
package com.example.test.test;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MiscTab extends Fragment {
private static final String TAG = "MiscTab";
private View root;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup @Nullable Bundle savedInstanceState) {
// Find the root view, and put in into a variable for later use by other functions
this.root = inflater.inflate(R.layout.misc_tab, container, false); //creates this.setupButton(R.id.misc_dead_bot_int, R.id.misc_dead_bot_plus, 0, 1, 1);
this.setupButton(R.id.misc_dead_bot_int, R.id.misc_dead_bot_minus, 0, 1, -1);
this.setupButton(R.id.misc_disabled_bot_int, R.id.misc_disabled_bot_plus, 0, 1, 1);
this.setupButton(R.id.misc_disabled_bot_int, R.id.misc_disabled_bot_minus, 0, 1, -1);
this.setupButton(R.id.misc_tipped_bot_int, R.id.misc_tipped_bot_plus, 0, 1, 1);
this.setupButton(R.id.misc_tipped_bot_int, R.id.misc_tipped_bot_minus, 0, 1, -1);
this.setupButton(R.id.misc_didnt_show_int, R.id.misc_didnt_show_plus, 0, 1, 1);
this.setupButton(R.id.misc_didnt_show_int, R.id.misc_didnt_show_minus, 0, 1, -1);
return this.root;
}
private void setupButton(int textID, int buttonID, final int minimum, final int maximum, final int stepValue) {
// Find the button from the view
Button button = this.root.findViewById(
// Find the buttons textview from the view
final TextView text = this.root.findViewById(
// Set the buttons actions to increase the count by the step value
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View
// Find the text views current value. If there is an error, assume 0
int initialCount;
try {
initialCount = Integer.parseInt(text.getText().toString());
} catch (Exception e) {
e.printStackTrace();
initialCount = 0;
}
// Calculate the final count value
int finalCount = initialCount + stepValue;
// Check if it matches the bounds
if (finalCount > maximum) {
finalCount = maximum;
}
if (finalCount < minimum) {
finalCount = minimum;
}
// Update the text to display the new final count
text.setText(String.valueOf(finalCount));
}
});
}
}
Соответствующий код в моем MainActivity.java
Bundle arguments = new Bundle();
arguments.putInt(MiscTab.misc_dead_bot_int);
Когда я пытаюсь передать MiscTab.misc_dead_bot_int
аргументам для putInt, он сообщаетменя это не может решить.Я предполагаю, что это потому, что он нигде не инициализирован, а просто следует за строкой в XML.Я не уверен, что я могу сделать, чтобы получить эти значения в отправляемом формате.Я попытался отправить его в строку, но единственное полученное значение вместо этого было большим числом.