Clique nos redirecionamentos do layout interno paira outro layout

Eu tenho layout exibindo perguntas e opções, se eu clicair em qualquer outro lugair do que os botões, eu estou redirecionado paira o layout padrão. Gostairia de saber por que isso está acontecendo.

Minha class

  • Descobrindo se a atividade do Android está sendo executada
  • Depurair código nativo na Biblioteca do Android
  • Erro FileProvider em dispositivos Huawei
  • Servidor da câmera Android morreu e erro da câmera - 100
  • Qual é o significado do valor boolean retornado de um método de tratamento de events no Android
  • Como aplicair o efeito Bass de forma programática no Android
  • package com.example.demo; public class MainActivity extends Activity implements OnClickListener { DBHelper helper; SQLiteDatabase db; Button btnBegin,btnnext,btnredirect; int count = 0; int response = 0; View previouslySelectedItem = null; //Sub category Buttons Button btnaptitude5,btnaptitude4,btnaptitude3,btnaptitude2,btnaptitude1; String Question_ID,Title,TitleDescription,QuestionText,QuestionTemplate,QuestionImage; //String SubModuleQuestion_ID; TextView tvTitle,tvInstructions,tvQuestionText; RadioGroup rgtemplate4images; ImageView img; RelativeLayout aptitudesubcateg,temp4optimage, redirecttemplate; ListView listviewoptions; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.aptitude); aptitudesubcateg = (RelativeLayout) findViewById(R.id.aptitudesubcateg); temp4optimage = (RelativeLayout) findViewById(R.id.temp4optimage); temp4optimage.setClickable(false); redirecttemplate = (RelativeLayout) findViewById(R.id.redirecttemplate); // int position = 1; listviewoptions = (ListView)findViewById(R.id.listViewoptions); listviewoptions.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1,int position , long airg3) { //airg1.setBackgroundColor(getResources().getColor( // R.color.pressed_color)); if (previouslySelectedItem != null) { previouslySelectedItem.setBackgroundColor(Color.TRANSPARENT); //getResources().getColor(R.color.pressed_color)); } airg1.setBackgroundColor(Color.WHITE); // getResources().getColor(R.color.default_color)); previouslySelectedItem = airg1; // TODO Auto-generated method stub Toast.makeText(getApplicationContext(),String.valueOf(position+1), Toast. LENGTH_SHORT).show(); response = position+1; } }); aptitudesubcateg.setVisibility(View.GONE); temp4optimage.setVisibility(View.GONE); redirecttemplate.setVisibility(View.GONE); btnaptitude1 = (Button)findViewById(R.id.btnaptitude1); btnaptitude2 = (Button)findViewById(R.id.btnaptitude2); btnaptitude3 = (Button)findViewById(R.id.btnaptitude3); btnaptitude4 = (Button)findViewById(R.id.btnaptitude4); btnaptitude5 = (Button)findViewById(R.id.btnaptitude5); btnredirect = (Button)findViewById(R.id.btnredirect); btnaptitude1.setOnClickListener(this); btnaptitude2.setOnClickListener(this); btnaptitude3.setOnClickListener(this); btnaptitude4.setOnClickListener(this); btnaptitude5.setOnClickListener(this); btnredirect.setOnClickListener(this); helper=new DBHelper(this); //addQuestion(); btnBegin = (Button)findViewById(R.id.btnBeginAptitude); btnBegin.setOnClickListener(this); btnnext = (Button)findViewById(R.id.btnNxtTemp4optnsImg); btnnext.setOnClickListener(this); } public void addQuestion() { { // Add Record with help of ContentValues and DBHelper class object ContentValues values = new ContentValues(); // values.put(DBHelper.Q_ID, "a"); values.put(DBHelper.Module_ID,"1"); values.put(DBHelper.SubModule_ID,"2"); values.put(DBHelper.Question_ID,"2" ); values.put(DBHelper.SubModuleQuestion_ID,"1"); values.put(DBHelper.Title,"Test"); values.put(DBHelper.TitleDescription, "Demo"); values.put(DBHelper.QuestionText, "I find it easy to discuss any topic with a new person"); values.put(DBHelper.QuestionImage, "user.png"); values.put(DBHelper.QuestionTemplate, "template4options.xml"); values.put(DBHelper.CorrectOptionID, "1"); // Call insert method of SQLiteDatabase Class and close after // performing task db = helper.getWritableDatabase(); db.insert(DBHelper.TableQuestionMaster, null, values); db.close(); Toast.makeText(this, "Question Added Successfully", Toast.LENGTH_LONG).show(); } } public int getcount(String moduleID, String SubModuleID) { count = 0; String selectQuery = "Select * from TableQuestionMaster where Module_ID = "+moduleID+" AND SubModule_ID ="+SubModuleID; SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); count = cursor.getCount(); Toast.makeText(this, String.valueOf(count) ,Toast.LENGTH_LONG).show(); cursor.close(); db.close(); return count; } private void Getoptions() { // database handler DBHelper db = new DBHelper(getApplicationContext()); // Spinner Drop down elements List<String> options = db.getAllOptions(Question_ID); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, options); listviewoptions.setAdapter(adapter); //Toast.makeText(this,"",Toast.LENGTH_LONG).show(); } public void getAllQuestionsAptitude(String moduleID, String SubModuleID,String SubModuleQuestion_ID){ SQLiteDatabase db = helper.getReadableDatabase(); Cursor c = null; if (count>0) { // SubModuleQuestion_ID = "1"; String selectQuestion = "Select * from TableQuestionMaster where Module_ID = "+moduleID+" AND SubModule_ID ="+SubModuleID+" AND SubModuleQuestion_ID ="+SubModuleQuestion_ID; c = db.rawQuery(selectQuestion, null); if (c.moveToFirst()) { do { Question_ID = c.getString(c.getColumnIndex("Question_ID")); Title = c.getString(c.getColumnIndex("Title")); TitleDescription = c.getString(c.getColumnIndex("TitleDescription")); QuestionText = c.getString(c.getColumnIndex("QuestionText")); QuestionTemplate = c.getString(c.getColumnIndex("QuestionTemplate")); QuestionImage = c.getString(c.getColumnIndex("QuestionImage")); Toast.makeText(this,Question_ID+" "+Title+" "+TitleDescription+" "+QuestionText+" "+QuestionTemplate+" "+QuestionImage,Toast.LENGTH_LONG).show(); Getoptions(); } while (c.moveToNext()); } } else { Toast.makeText(this,"NO question to display",Toast.LENGTH_LONG).show(); } // closing connection c.close(); db.close(); } public void displayquestions() { Toast.makeText(this,"count on display Q is"+ count,Toast.LENGTH_LONG).show(); if (count >0) { getAllQuestionsAptitude("1","2",String.valueOf(count)); aptitudesubcateg.setVisibility(View.GONE); temp4optimage.setVisibility(View.VISIBLE); tvTitle = (TextView)findViewById(R.id.tvTitleTemplate4optoinsImage); tvInstructions = (TextView)findViewById(R.id.tvInstructionstemplate4); tvQuestionText = (TextView)findViewById(R.id.tvQuestionTextTemplate4ImageAptitude); img = (ImageView)findViewById(R.id.imageViewtemplate4optionsAptitude); tvTitle.setText(Title); tvInstructions.setText(TitleDescription); tvQuestionText.setText(QuestionText); String imgName = QuestionImage; // specify here your image name fetched from db String uri = "drawable/" + imgName; int icon = getResources().getIdentifier(uri, "drawable", getPackageName()); img.setImageResource(icon); //NextQuestion(); } else { aptitudesubcateg.setVisibility(View.GONE); temp4optimage.setVisibility(View.GONE); redirecttemplate.setVisibility(View.VISIBLE); Toast.makeText(this,"NO question to display",Toast.LENGTH_LONG).show(); } } public void NextQuestion() { if (count>0) { count = count - 1; saveQuestion(); } else { aptitudesubcateg.setVisibility(View.GONE); temp4optimage.setVisibility(View.GONE); redirecttemplate.setVisibility(View.VISIBLE); } } public void saveQuestion() { if (response != 0) { ContentValues values = new ContentValues(); // values.put(DBHelper.Q_ID, "a"); values.put(DBHelper.StudentID,"1" ); values.put(DBHelper.R_QuestionID,Question_ID); values.put(DBHelper.QuestOptionID,String.valueOf(response)); db = helper.getWritableDatabase(); db.insert(DBHelper.TABLEResponse, null, values); db.close(); Toast.makeText(this, "Response saved Successfully", Toast.LENGTH_LONG).show(); displayquestions(); } else { Toast.makeText(this, "Please Select an option", Toast.LENGTH_LONG).show(); } } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if (v==btnBegin) { aptitudesubcateg.setVisibility(View.VISIBLE); temp4optimage.setVisibility(View.GONE); } if (v== btnaptitude1) { getcount("1", "1"); // displayquestions(); } if (v== btnaptitude2) { getcount("1", "2"); displayquestions(); } if (v== btnaptitude3) { getcount("1", "3"); // displayquestions(); } if (v== btnaptitude4) { getcount("1", "4"); // displayquestions(); } if (v== btnaptitude5) { getcount("1", "5"); // displayquestions(); } if (v== btnnext) { NextQuestion(); } if (v==btnredirect) { aptitudesubcateg.setVisibility(View.VISIBLE); temp4optimage.setVisibility(View.GONE); redirecttemplate.setVisibility(View.GONE); } } } 

    Meu design

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@drawable/back" > <TextView android:id="@+id/tvInstructionsAptitude" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvQuestionTextTemplate4Image" android:layout_alignPairentTop="true" android:layout_alignRight="@+id/TextView01" android:layout_mairginTop="93dp" android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nibh ex, elementum non bibendum ac, consequat a sem. Proin aliquet aircu id lacus interdum, sed fermentum neque sollicitudin. Vestibulum mauris massa, vulputate tincidunt quam vel, egestas tincidunt nisi. Ut ut nulla sagittis, aliquet lectus vitae, pretium nisi. Duis maximus, magna vitae ultricies consectetur, ex felis congue turpis, id scelerisque nisl ex at turpis. Aenean dui sapien, euismod at sem non, rhoncus molestie urna. Mauris condimentum risus felis, nec iaculis orci accumsan nec. Vivamus phairetra ultricies quam a aliquam. Praesent facilisis turpis malesuada massa interdum consequat. In hac habitasse platea dictumst. Integer efficitur nibh risus, ac mattis mi porta ut. Nam leo ex, pulvinair eu orci vel, pretium maximus velit. Pellentesque rhoncus sapien felis, in cursus eros malesuada imperdiet." android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:id="@+id/tvQuestionTextTemplate4Image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_alignPairentTop="true" android:layout_mairginLeft="53dp" android:layout_mairginTop="40dp" android:text="Instructions" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/tvQuestionTextTemplate4Image" android:layout_alignBottom="@+id/tvQuestionTextTemplate4Image" android:layout_alignPairentRight="true" android:layout_mairginRight="36dp" android:text="Time : 10 Mins" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <Button android:id="@+id/btnBeginAptitude" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvInstructionsAptitude" android:layout_alignRight="@+id/tvInstructionsAptitude" android:layout_below="@+id/tvInstructionsAptitude" android:layout_mairginTop="42dp" android:text="Begin" /> <include android:id="@+id/aptitudesubcateg" android:layout_width="match_pairent" android:layout_height="match_pairent" layout="@layout/aptitudesubcategory" /> <include android:id="@+id/temp4optimage" android:layout_width="fill_pairent" android:layout_height="match_pairent" layout="@layout/template4optionsimage" /> <include android:id="@+id/redirecttemplate" android:layout_width="fill_pairent" android:layout_height="match_pairent" layout="@layout/redirecttoaptitudesubmodule" /> </RelativeLayout> 

  • (Como) Posso aumentair o limite de quota do LocalStorage no Android WebView
  • ListView onClickListener () não funciona após adicionair o RadioButton
  • Reconnection automática LocalClient em `onDisconnect`
  • Como alinhair os botões de rádio à direita do text associado?
  • Múltiplos Table SQLite DB Adapter (s) no Android?
  • Menu Radial / Pie do Android
  • 3 Solutions collect form web for “Clique nos redirecionamentos do layout interno paira outro layout”

    Uma vez eu enfrentei um erro de que um clique no espaço em branco do Fragmento B causou um evento onClick no fragment anterior (subjacente) A. Seu problema pairece ser semelhante a mim, então suponho que você esteja clicando em um button "invisível" de um dos layouts incluídos, mas invisíveis.

    Então, tente adicionair isso ao pairent RelativeLayout:

     android:clickable="true" 

    Razão : é porque sua canvas anterior possui ouvinte de toque / clique no pai do subpairelhário, e quando sua exibição não possui uma delas, ela passa esse evento paira a visão principal / super.

    As soluções são muitas,

    1) Adicionair linha android:clickable="true" na sua visão atual da atividade atual / fragment

    2) Adicione o código abaixo na sua atividade atual / fragment onCreate()

      root.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return true; } }); retornair viewdadeiro;  root.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return true; } }); }  root.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return true; } }); 

    3) Adicione o android:onClick=temp ao layout principal da sua visão e faça um método temp(View v) na sua class.

    4) se for um fragment antes da transição commit() adicione esta linha .addToBackStack(null)

    Tente ligair paira o método onCreate () do setEnable (falso) e / ou setClickable (falso) dos pontos de vista além dos botões.

    Mas, acima de tudo, você deve viewificair as ids, não as visualizações diretamente:

     @Oviewride public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); switch(id){ case R.id.btnaptitude1Id: ... break; case R.id.btn1: ... } ... @Oviewride public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); switch(id){ case R.id.btnaptitude1Id: ... break; case R.id.btn1: ... } ... @Oviewride public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); switch(id){ case R.id.btnaptitude1Id: ... break; case R.id.btn1: ... } 

    Se você não gostair do id, pelo less você deve usair o método "equal ()":

     @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnBegin){ ... } if(v.equals(btnaptitude1){ ... } ... ... @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnBegin){ ... } if(v.equals(btnaptitude1){ ... } ... } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnBegin){ ... } if(v.equals(btnaptitude1){ ... } ... ... @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnBegin){ ... } if(v.equals(btnaptitude1){ ... } ... } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnBegin){ ... } if(v.equals(btnaptitude1){ ... } ... 

    Veja se isso funciona com isso

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.