I have BottomSheetDialog layout xml file which been called by my activity. And BottomSheetDialog has 2 buttons. On clicking on button inside BottomSheetDialog it should take me to another Activity.
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.ezeelearn.colorstonz.ezeelearn.PhysicsTestSelectorActivity"
tools:showIn="#layout/app_bar_physics_lesson">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="#+id/lesson_list">
</TableLayout>
</ScrollView>
<include layout="#layout/bottom_sheet_layout" />
</LinearLayout>
bottom_sheet_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/RelativeLayoutSheet"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/bottom_sheet_behavior"
android:background="#ffffff"
app:behavior_hideable="true"
android:padding="20dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:paddingRight="50dp"
android:paddingLeft="50dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="#drawable/google_cardboard"
android:drawablePadding="6dp"
android:gravity="left|center"
android:height="60dp"
android:padding="6dp"
android:text="Video"
android:id="#+id/bottom_sheet_video_btn"
android:textAlignment="center"
android:fontFamily="sans-serif-light"
android:foreground="?android:attr/selectableItemBackground"
android:textColor="#666" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:paddingRight="50dp"
android:paddingLeft="50dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#fff"
android:drawableTop="#drawable/bulletin_board"
android:drawablePadding="6dp"
android:gravity="left|center"
android:height="60dp"
android:padding="6dp"
android:text="Lesson"
android:id="#+id/bottom_sheet_lesson_btn"
android:textAlignment="center"
android:fontFamily="sans-serif-light"
android:foreground="?android:attr/selectableItemBackground"
android:textColor="#666" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity{
BottomSheetDialog bottomSheetDialog;
BottomSheetBehavior bottomSheetBehavior ;
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
List<String> lessonNames = new ArrayList<String>();
lessonNames.add("Photosynthesis in Higher Plants");
lessonNames.add("The Living World");
lessonNames.add("Biological Classification");
lessonNames.add("Plant Kingdom");
lessonNames.add("Animal Kingdom");
lessonNames.add("Morphology of Flowering Plants");
lessonNames.add("Anatomy of Flowering Plants");
lessonNames.add("Structural Organisation in Animals");
lessonNames.add("Cell-The Unit of Life");
lessonNames.add("Biomolecules");
lessonNames.add("Transport in Plants");
lessonNames.add("Mineral Nutrition");
lessonNames.add("Flowering Plants");
TableLayout lessonList = (TableLayout) findViewById(R.id.lesson_list);
List<TableLayout> lessonTableList = new ArrayList<TableLayout>();
for(int i = 0; i < lessonNames.size(); i++) {
TableRow tableRow = new TableRow(this);
TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
tableRow.setLayoutParams(tableLayoutParams);
tableRow.setPadding(30, 25, 30, 25);
tableRow.setBackgroundDrawable(getResources().getDrawable(R.drawable.textlines));
TextView textView = new TextView(this);
textView.setText(String.format("%02d", (i+1))+". "+lessonNames.get(i));
/*textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_dots_vertical, 0);*/
textView.setTextSize(17);
tableRow.addView(textView);
/*TextView textView = new TextView(this);
textView.setText(String.format("%02d", (i+1))+". "+lessonNames.get(i));
textView.setPadding(20, 25, 20, 25);
textView.setTextSize(17);
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_dots_vertical, 0);
textView.setLayoutParams(new TableLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.textlines));
lessonList.addView(textView);*/
lessonList.addView(tableRow);
lessonTableList.add(lessonList);
}
for(final TableLayout tableLayout: lessonTableList) {
tableLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bottomSheetDialog = new BottomSheetDialog(PhysicsLessonActivity.this);
View view = getLayoutInflater().inflate(R.layout.bottom_sheet_layout, null);
bottomSheetDialog.setContentView(view);
bottomSheetDialog.show();
bottomSheetDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
#Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
Log.d("BottomSheetVideoBtn", "called");
return false;
}
});
}
});
}
Button bottomSheetVideoBtn = (Button) findViewById(R.id.bottom_sheet_video_btn);
Button bottomSheetLessonBtn = (Button) findViewById(R.id.bottom_sheet_lesson_btn);
bottomSheetVideoBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), PhysicsActivity.class);
Log.d("BottomSheetVideoBtn", "called");
startActivity(intent);
}
});
bottomSheetLessonBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Lesson Button Clicked", Toast.LENGTH_LONG).show();
}
});
ImageButton backToPHome = (ImageButton) findViewById(R.id.back_to_home);
backToPHome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), PhysicsActivity.class);
startActivity(intent);
}
});
}
}
Use this
public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false);
Button btn1 = (Button)v.findViewById(R.id.btn1);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getActivity(),YourActivity.class));
}
});
return v;
}
}
Then call this bottomSheet in your activity by
new CustomBottomSheetDialogFragment().show(getSupportFragmentManager(), "Dialog");
rather than create new class, how about this one
final BottomSheetDialog dialog = new BottomSheetDialog(YourActivity.this);
dialog.setContentView(R.layout.your_bottomsheet_layout);
dialog.setCanceledOnTouchOutside(false);
ImageButton btnClose = (ImageButton) dialog.findViewById(R.id.button_close);
btnClose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
Button bottomSheetVideoBtn = (Button) view.findViewById(R.id.bottom_sheet_video_btn);
Button bottomSheetLessonBtn = (Button) view.findViewById(R.id.bottom_sheet_lesson_btn);
Related
I have an FragmentActivity which contain WebView, Edittext1, Edittext2, Checkboxes and button. When I click the button in fragment it will move to Results_activity. And if I click button from Results_activity it move back to FragmentActivity.
But my edittext values getting cleared while moving back.
FragmentActivity xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:id="#+id/questionContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="#+id/questionWV"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansA_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansB_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/answers_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="#+id/answer_a_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="0"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta A"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_b_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_marginStart="15dp"
android:hint="1"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta B"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_c_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="2"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta C"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_d_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="3"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta D"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"
android:orientation="horizontal"
android:paddingBottom="30dp">
<Button
android:id="#+id/btnFinishTest"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="FinishTest"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Finish Test" />
<Button
android:id="#+id/btnAnswer"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="SubmitAnswer"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Submit Answer" />
</LinearLayout>
</LinearLayout>
Fragment Code
my edittexts are et1 and et2
public class QuestionFragment2018ii extends Fragment {
LinearLayout answersContainer;
int currentPageNr;
private String input1;
#Override
public View onCreateView(LayoutInflater lInflater, ViewGroup container,Bundle saveInstanceState){
currentPageNr = getArguments().getInt("position");
//initialize some variables
final Question2018ii currentQuestion2018ii = MyServerData2018ii.getInstance().getQuestion(currentPageNr);
View rootView = lInflater.inflate(R.layout.quiz_activity_fragment,container,false);
//initialize show answer option
final String ans = currentQuestion2018ii.getExplanationText();
final EditText et1 = rootView.findViewById(R.id.ansA);
final EditText et2 = rootView.findViewById(R.id.ansB);
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
et1.setText("Your Response: " + et.getText());
et2.setText("Correct Answer: " + ans);
}
//initialize Explanation option
//initialize answers
answersContainer = (LinearLayout)rootView.findViewById(R.id.answers_container);
String[] answers = currentQuestion2018ii.getAllAnswersText();
for (int i = 0; i < answersContainer.getChildCount(); i++) {
RelativeLayout checkboxContainer = (RelativeLayout)answersContainer.getChildAt(i);
CheckBox cb = (CheckBox)checkboxContainer.getChildAt(0);
cb.setMovementMethod(new ScrollingMovementMethod());
cb.setText(answers[i]);
cb.setChecked(currentQuestion2018ii.isChecked(i));
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
cb.setEnabled(false);
questionWebView.loadUrl("file:///android_asset/" + currentQuestion2018ii.getSolutionText());
//check if answer is right or wrong
if(currentQuestion2018ii.isCorrectAnswer(i)){
cb.setTextColor(Color.parseColor("#4DAD47"));
cb.setTypeface(null, Typeface.BOLD);
} else {
cb.setTextColor(Color.parseColor("#CE0B0B"));
}
}else{
cb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckBox cb = ((CheckBox) v);
int number = Integer.parseInt(cb.getHint().toString());
currentQuestion2018ii.setChecked(number, cb.isChecked());
}
});
}
}
return rootView;
}
}
ResultsActivity xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="30dp"
android:text="#string/results"
android:textColor="#4DAD47"
android:textSize="20sp"
android:textStyle="bold|italic" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="30dp" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="#string/correct_answers" />
</LinearLayout>
<TextView
android:id="#+id/myTotalAnswers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:paddingRight="5dp"
android:text="50/100" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainContainer"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="#+id/check_results"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/check_results" />
<Button
android:id="#+id/btnMainMenu"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/main_menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Quiz activity
public class QuizActivity2018ii extends AppCompatActivity {
Spinner spinCategory;
EditText questionNr;
ArrayList<String> allCategories;
int totalQuestions;
AlertDialog dialog;
ViewPager pager;
QuestionPagerAdapter2018ii pagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz_activity_view_pager);
allCategories = new ArrayList<>(MyServerData2018ii.getInstance().getCategoryList());
totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
//initialize category spinner
ArrayAdapter<String> categoryAdapter = new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item,allCategories);
spinCategory = (Spinner) findViewById(R.id.category);
spinCategory.setAdapter(categoryAdapter);
spinCategory.setSelection(0);
//set Category spinner callback
spinCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String currentQuestionRealCategory = MyServerData2018ii.getInstance().getQuestionCategory(pager.getCurrentItem());
String selectedCategory = spinCategory.getItemAtPosition(position).toString();
if (!selectedCategory.equals(currentQuestionRealCategory)) {
int firstQuestionNumberFromCategory = MyServerData2018ii.getInstance().getFirstQuestionNumberFromCategory(selectedCategory);
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(firstQuestionNumberFromCategory, false);
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//initialize number
questionNr = (EditText) findViewById(R.id.dialog_question_number);
questionNr.clearFocus();
//set number callbacks
questionNr.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_ENTER)) {
v.clearFocus();
CharSequence s = questionNr.getText();
if (!s.toString().isEmpty()) {
Integer questionNumber = Integer.parseInt(s.toString());
//avoids out of range indexes
if (questionNumber > totalQuestions + 1) {
questionNumber = totalQuestions;
}
if (questionNumber < 0) {
questionNumber = 1;
}
//create looping effect
if (questionNumber == totalQuestions + 1) {
questionNumber = 1;
((EditText)v).setText("1");
}
if (questionNumber == 0) {
questionNumber = totalQuestions;
((EditText)v).setText(String.valueOf(totalQuestions));
}
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(questionNumber, false);
questionNr.clearFocus();
} else {
questionNr.setText("1");
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return false;
}
});
//initialize pager
pager = (ViewPager)findViewById(R.id.qPager);
pagerAdapter = new QuestionPagerAdapter2018ii(getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
pager.setCurrentItem(1, false);
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
#Override
public void onPageSelected(int position) {
Integer currentQuestion = pager.getCurrentItem();
//change spinner
String currentCategory = MyServerData2018ii.getInstance().getQuestionCategory(currentQuestion);
int categoryPosition = MyServerData2018ii.getInstance().getCategoryList().indexOf(currentCategory);
spinCategory.setSelection(categoryPosition);
//change numberPicker
if(currentQuestion <= 0){currentQuestion = totalQuestions;}
if(currentQuestion > totalQuestions){currentQuestion = 1;}
questionNr.setText(currentQuestion.toString());
questionNr.clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(questionNr.getWindowToken(), 0);
}
#Override
public void onPageScrollStateChanged(int state) {
int totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
if (state == ViewPager.SCROLL_STATE_IDLE) {
if (pager.getCurrentItem() == totalQuestions + 1) {
pager.setCurrentItem(1, false);
}
if (pager.getCurrentItem() == 0) {
pager.setCurrentItem(totalQuestions, false); // false will prevent sliding animation of view pager
}
}
}
});
}
public void FinishTest(View v){
//check if there are unanswered questions
if(MyServerData2018ii.getInstance().getTestState().equals("inProgress")){
ArrayList<String> UnansweredQuestions = new ArrayList<>();
LinkedHashMap<String,Object> allQuestions = MyServerData2018ii.getInstance().getAllQuestions();
for(Map.Entry category: allQuestions.entrySet()){
Question2018ii[] question2018iis = (Question2018ii[])category.getValue();
for(int i = 0; i < question2018iis.length; i++){
Boolean[] userAnswers = question2018iis[i].getUserAnswers();
if(!Arrays.asList(userAnswers).contains(true)){
String checkedCategory = (String)category.getKey();
Integer questionNumberInList = MyServerData2018ii.getInstance().getQuestionListNumber(checkedCategory,i);
UnansweredQuestions.add(String.valueOf(questionNumberInList));
}
}
}
if(UnansweredQuestions.size() > 0){
dialog = new AlertDialog.Builder(this)
.create();
LayoutInflater infl = LayoutInflater.from(this);
dialog.setView(infl.inflate(R.layout.dialog_message,null));
dialog.show();
TextView message = (TextView)dialog.findViewById(R.id.message);
String unfinished = getResources().getString(R.string.unfinished_text);
String questions = TextUtils.join(",",UnansweredQuestions);
message.setText(unfinished + "\n" + questions + ".");
dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
showResults();
}
});
}else{showResults();}
}else{
showResults();
}
}
public void showResults(){
int animationDuration;
if(MyServerData2018ii.getInstance().getTestState().equals("finished")){
animationDuration = 10;
}else{
animationDuration = 2000;
}
View mainView = LayoutInflater.from(this).inflate(R.layout.quiz_activity_show_results,null);
LinearLayout mainContainer = (LinearLayout)mainView.findViewById(R.id.mainContainer);
mainView.findViewById(R.id.btnMainMenu).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//finish the test and go to main menu
Intent Main = new Intent(getApplicationContext(),MainActivity.class);
finish();
startActivity(Main);
MyServerData2018ii.getInstance().setTestState("notStarted");
MyServerData2018ii.getInstance().clearAnswers();
Toast.makeText(getBaseContext(),R.string.text_ended,Toast.LENGTH_LONG).show();
}
});
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
Question2018ii[] currentCategory;
int totalCategoryQuestions;
int correctCategoryQuestions;
int totalCorrectQuestions = 0;
//checking and adding each category
for(String category: allCategories){
View categoryContainer = LayoutInflater.from(this).inflate(R.layout.quiz_activity_category_results,null);
TextView categoryName = (TextView)categoryContainer.findViewById(R.id.categoryName);
//set name
categoryName.setText(category);
currentCategory = MyServerData2018ii.getInstance().getCategory(category);
totalCategoryQuestions = currentCategory.length;
//check answers
correctCategoryQuestions = 0;
for(int i=0; i < currentCategory.length;i++){
Boolean isCorrect = Arrays.equals(currentCategory[i].getAllCorrectAnswers(),currentCategory[i].getUserAnswers());
if(isCorrect){ correctCategoryQuestions++;}
}
totalCorrectQuestions += correctCategoryQuestions;
//set results
String result = String.valueOf(correctCategoryQuestions) + "/" + String.valueOf(totalCategoryQuestions);
final ProgressBar progress = (ProgressBar)categoryContainer.findViewById(R.id.progressBar);
progress.setMax(totalCategoryQuestions*100);
final TextView myResult = (TextView)categoryContainer.findViewById(R.id.categoryResult);
final String myResultText = "/" + String.valueOf(totalCategoryQuestions);
ValueAnimator val = new ValueAnimator();
val.setObjectValues(0, correctCategoryQuestions*100);
val.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
myResult.setText(String.valueOf((Integer)animation.getAnimatedValue()/100) + myResultText);
progress.setProgress( ((Integer) animation.getAnimatedValue()));
}
});
val.setDuration(animationDuration);
val.start();
mainContainer.addView(categoryContainer);
}
//animate results
final TextView tvTotalResult =(TextView)mainView.findViewById(R.id.myTotalAnswers);
final String totalResultS = "/" + String.valueOf(totalQuestions);
ValueAnimator totalResultsAnimator = new ValueAnimator();
totalResultsAnimator.setObjectValues(0, totalCorrectQuestions);
totalResultsAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
tvTotalResult.setText(String.valueOf(animation.getAnimatedValue()) + totalResultS);
}
});
totalResultsAnimator.setDuration(animationDuration);
totalResultsAnimator.start();
MyServerData2018ii.getInstance().setTestState("finished");
setContentView(mainView);
}
}
this is my question yearwise activity(from this I launched the fragment activity)
public class QuestionYearwise extends AppCompatActivity{
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.question_yearwise);
Button btn2018ii = (Button)findViewById(R.id.btn2018ii);
btn2018ii.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent Quiz2018ii = new Intent(getApplicationContext(),QuizActivity2018ii.class);
MyServerData2018ii.getInstance().setTestState("inProgress");
startActivity(Quiz2018ii);
}
});
}
}
Replace the method like this,
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
I`m new in android programming, I created add_layout.xml and what I want is to add it in activity_main.xml below each other by onClick each time the button clicked.
here is the codes:
add_layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/addRoot">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World..."
android:id="#+id/plainText"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_below="#id/plainText"
android:layout_marginTop="16dp"/>
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.app.androidstudio.addlayout.MainActivity">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/add"
android:text="Add"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/addAnother"
android:text="Add another"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="false" />
MainActivity.java:
public class MainActivity extends AppCompatActivity {
Button add, addAnother;
RelativeLayout activity_main;
RelativeLayout add_layout;
TextView plainText;
boolean clickAgain;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add = (Button) findViewById(R.id.add);
addAnother = (Button) findViewById(R.id.addAnother);
plainText = (TextView) findViewById(R.id.plainText);
add_layout = (RelativeLayout) findViewById(R.id.addRoot);
activity_main = (RelativeLayout) findViewById(R.id.activity_main);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final RelativeLayout newLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.add_layout, null);
activity_main.addView(newLayout);
}
});
addAnother.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//?????????????
}
});
}
}
Thanks for help...
Change This
activity_main.addView(newLayout);
To
activity_main.appendView(newLayout);
And also change the Layout of activity_main from RelativeLayout to LinearLayout (Virticle)
Change the RelativeLayout of Activity_Main.xml With LinearLayout with orientation vertical.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
orientation="vertical"
tools:context="com.app.androidstudio.addlayout.MainActivity">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/add"
android:text="Add"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/addAnother"
android:text="Add another"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="false" />
</LinearLayout>
and your MainActivity
public class MainActivity extends AppCompatActivity {
Button add, addAnother;
LinearLayout activity_main;
RelativeLayout add_layout;
TextView plainText;
boolean clickAgain;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add = (Button) findViewById(R.id.add);
addAnother = (Button) findViewById(R.id.addAnother);
plainText = (TextView) findViewById(R.id.plainText);
add_layout = (RelativeLayout) findViewById(R.id.addRoot);
activity_main = (LinearLayout) findViewById(R.id.activity_main);
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final RelativeLayout newLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.add_layout, null);
activity_main.addView(newLayout);
}
});
addAnother.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//?????????????
}
});
}
I have a RecyclerView list of CardViews. I click on a CardView and it uses an intent to launch a new activity, which shows a detail CardView to the user. I want to add a LongClick to that new CardView that will launch a Dialog to ask the user if they would like to delete the CardView. I tried the set up below. The Dialog does not launch and I don't see the Toast. What am I missing here?
public class CardViewDetails extends AppCompatActivity {
int position;
CardView cardView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
CardView cardView = (CardView) findViewById(detsinglecard_view);
cardView.setOnClickListener((View.OnClickListener) this);
cardView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Toast.makeText(CardViewDetails.this,"Dialog Test",Toast.LENGTH_SHORT).show();
android.app.FragmentManager fm = getFragmentManager();
DeleteCardViewFragment delCardViewDialog = new DeleteCardViewFragment();
delCardViewDialog.show(fm,"delcardview dialog");
return true;
}
});
activity_details:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#FFFFFF"
tools:context="com.wimso.v060B.CardViewDetails">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" >
</include>
<RelativeLayout
android:id="#+id/cardViewDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background4main"
android:layout_marginTop="6dp"
android:layout_marginStart="6dp"
android:layout_marginLeft="6dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="2dp"
android:textStyle="bold"
android:textColor="#color/colorFlLabelFinal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:clickable="false"
android:layout_centerHorizontal="true" />
<Spinner
android:id="#+id/skycard_filter2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Base.Widget.AppCompat.Spinner" />
**strong text**<android.support.v7.widget.CardView**strong text**
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
**strong text**android:id="#+id/detsinglecard_view"**strong text**
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
card_view:cardBackgroundColor="#android:color/white"
card_view:cardCornerRadius="6dp"
card_view:cardElevation="4dp"
android:longClickable="true" >
...
You have to call setContentView() in onCreate() before accessing elements via findViewById()
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
CardView cardView = (CardView) findViewById(detsinglecard_view);
cardView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Bundle bundle2 = new Bundle();
bundle2.putInt("itemPosition",position);
android.app.FragmentManager fm = getFragmentManager();
DeleteCardViewFragment delCardViewDialog = new DeleteCardViewFragment();
delCardViewDialog.setArguments(bundle2);
delCardViewDialog.show(fm,"delcardview dialog");
return true;
}
}
}
I have an Xml that add LinearLayout and RelativeLayout in ScrollView by programmatically.When i add Text with OnclickButton for first time show me message but for 2nd time get me crash :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollID"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:weightSum="1" >
<EditText
android:id="#+id/txtInpuConversation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:hint="Text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/btnSend"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Click" />
</LinearLayout>
</LinearLayout>
My code :
public class MainActivity extends Activity {
String Medtconversation;
EditText edtconversation;
TextView txtviewUser;
LinearLayout rilative;
RelativeLayout relativeLayout;
LinearLayout firstLinearLayout;
ScrollView sclView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtconversation = (EditText) findViewById(R.id.txtInpuConversation);
sclView = (ScrollView) findViewById(R.id.scrollID);
Button btn = (Button) findViewById(R.id.btnSend);
final Context context = this;
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Medtconversation = edtconversation.getText().toString();
txtviewUser = new TextView(MainActivity.this);
txtviewUser.setText(Medtconversation);
relativeLayout = new RelativeLayout(context);
firstLinearLayout= new LinearLayout(context);
LayoutParams LLParamsT = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
relativeLayout.setLayoutParams(LLParamsT);
relativeLayout.addView(txtviewUser,
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
firstLinearLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams LLParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
firstLinearLayout.setLayoutParams(LLParams);
firstLinearLayout.addView(relativeLayout);
Crash here now======>sclView.addView(firstLinearLayout, new
LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
edtconversation.setText("");
}
});
}
}
I need that when i click on Button and send message for 2nd time create a new RelativeLayout in LinearLayout for show.(In scrollView)
Error :
AndroidRuntime
MainActivity$1.onClick(MainActivity.java:54)
mmmmm. I recommend that you using from table and you can add programmatically your TextView and etc. simply :
public class MainActivity extends Activity {
String Medtconversation;
EditText edtconversation;
TextView txtviewUser;
TextView txtviewUserT;
RelativeLayout relativeLayout;
LinearLayout firstLinearLayout;
TableRow tr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtconversation = (EditText) findViewById(R.id.txtInpuConversation);
Button btn = (Button) findViewById(R.id.btnSend);
final TableLayout tl = (TableLayout) findViewById(R.id.tbl);
final Context context = this;
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Medtconversation = edtconversation.getText().toString();
txtviewUser = new TextView(MainActivity.this);
txtviewUserT = new TextView(MainActivity.this);
txtviewUserT.setText("OK");
txtviewUser.setText(Medtconversation);
tr = new TableRow(context);
tr.addView(txtviewUser);
tr.addView(txtviewUserT);
tl.addView(tr);
edtconversation.setText("");
}
});
}
}
Your XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/xxx"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TableLayout
android:id="#+id/tbl"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:weightSum="1" >
<EditText
android:id="#+id/txtInpuConversation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:hint="Text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/btnSend"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Click" />
</LinearLayout>
</LinearLayout>
First you need to add the LinearLayout to ScrollView
Then add the relative layout to the LinearLayout
public class MainActivity extends Activity {
String Medtconversation;
EditText edtconversation;
TextView txtviewUser;
LinearLayout rilative;
RelativeLayout relativeLayout;
LinearLayout firstLinearLayout;
ScrollView sclView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtconversation = (EditText) findViewById(R.id.txtInpuConversation);
Button btn = (Button) findViewById(R.id.btnSend);
sclView = (ScrollView) findViewById(R.id.scrollID);
firstLinearLayout= new LinearLayout(this);
relativeLayout = new RelativeLayout(this);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Medtconversation = edtconversation.getText().toString();
txtviewUser = new TextView(MainActivity.this);
txtviewUser.setText(Medtconversation);
LayoutParams LLParamsT = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
relativeLayout.setLayoutParams(LLParamsT);
relativeLayout.addView(txtviewUser,
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
firstLinearLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams LLParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
firstLinearLayout.setLayoutParams(LLParams);
sclView.addView(firstLinearLayout);
firstLinearLayout.addView(relativeLayout);
sclView.addView(firstLinearLayout, new
LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
edtconversation.setText("");
}
});
}
}
You are creating a new LinearLayout and RelativeLayout only once (inside onCreate), however you add them multiple times. Instead create new instances from inside of the onClick method:
final Context context = this;
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
LinearLayout firstLinearLayout= new LinearLayout(context);
RelativeLayout relativeLayout = new RelativeLayout(context);
...
firstLinearLayout.addView(relativeLayout);
...
}
});
In my project need to make layout listview with edit text
please suggest me how i can make this kind of layout
Thanks In Advance
Any Help Is Appreciated
Use following code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/mylinear"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/group4ff"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/vazgecff"
android:layout_width="0dp"
android:layout_weight=".30"
android:layout_height="wrap_content"
android:onClick="cagir"
android:text="vazgec" />
<Button
android:id="#+id/kaydetff"
android:layout_width="0dp"
android:layout_weight=".70"
android:layout_height="wrap_content"
android:onClick="cagir"
android:text="kaydet" />
</LinearLayout>
</LinearLayout>
Activity.java
public class Form3 extends Activity {
LinearLayout[] llx ;
TextView[] tx ;
EditText[] ex ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form3);
DBHandler db = new DBHandler(this);
ArrayList<Siparis> listem = db.getSiparis();
db.close();
LinearLayout ll = (LinearLayout) findViewById(R.id.mylinear);
llx = new LinearLayout[listem.size()];
tx = new TextView[listem.size()];
ex = new EditText[listem.size()];
for (int i = 0; i < listem.size(); i++) {
llx[i] = new LinearLayout(this);
tx[i] = new TextView(this);
ex[i] =new EditText(this);
tx[i].setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT,0.8f));
ex[i].setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT,0.2f));
tx[i].setText(listem.get(i).getMalzeme_adi());
ex[i].setInputType(InputType.TYPE_CLASS_NUMBER);
llx[i].setId(i);
llx[i].setClickable(true);
final int j = i;
llx[i].setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
msg(tx[j].getText().toString());
}
});
llx[i].addView(tx[i]);
llx[i].addView(ex[i]);
ll.addView(llx[i]);
}
}
private void msg(String x){
Toast.makeText(this, x, Toast.LENGTH_LONG).show();
}
public void cagir(View view){
switch (view.getId()) {
case R.id.kaydetff:
for (int i = 0; i < ex.length; i++) {
if(!ex[i].getText().toString().equals("")){
Log.e(tx[i].getText().toString(),ex[i].getText().toString());
}
}
break;
default:
break;
}
}
}