0

Работает на Android Version - KITKAT. Проблема сохраняется, когда Button - newRide не запускает метод onClick(), тот же код работает очень хорошо на другом Android Version > KITKAT.Кнопка не запускается onClick метод

Java кода из моего класса:

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    View contentView = inflater.inflate(R.layout.activity_ongoing_ride_details, null, false); 
    View cView = getLayoutInflater().inflate(R.layout.title_bar, null); 

    imgSignOut = (ImageView) cView.findViewById(R.id.imgSignout); 
    imgRefresh = (ImageView) cView.findViewById(R.id.imgRefresh); 
    tvTitle = (TextView) cView.findViewById(R.id.tvTitle); 
    newRide = (Button)contentView.findViewById(R.id.btnNewRide); 

    if (Utilities.getStringFromPrefs(getApplicationContext(), "userType") 
     .equals("driver")) { 
     setContentView(contentView); 
     ActionBar actionBar = getActionBar(); 
     actionBar.setDisplayShowTitleEnabled(false); 
     actionBar.setDisplayUseLogoEnabled(false); 
     actionBar.setDisplayHomeAsUpEnabled(false); 
     actionBar.setDisplayShowCustomEnabled(true); 
     actionBar.setCustomView(cView); 

     actionBar.setBackgroundDrawable(
      new ColorDrawable(Color.parseColor("#ffffff"))); 
     tvTitle.setText("ON GOING RIDES"); 
     tvTitle.setTextColor(Color.BLACK); 
    } 
    else { 
     frameLayout.addView(contentView); 

     getActionBar().setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM 
      | android.support.v7.app.ActionBar.DISPLAY_SHOW_HOME | android.support.v7.app.ActionBar.DISPLAY_HOME_AS_UP); 
     getActionBar().setCustomView(R.layout.custom_title); 
     getActionBar().setHomeButtonEnabled(true); 
     getActionBar().setDisplayHomeAsUpEnabled(true); 
     getActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer); 
     getActionBar().setBackgroundDrawable(
      new ColorDrawable(Color.parseColor("#ffffff"))); 
     TextView headTxt = (TextView) findViewById(R.id.mytext); 
     headTxt.setTextColor(Color.BLACK); 
     headTxt.setText("ON GOING RIDES"); 

    } 

    lvRideList = (ListView) findViewById(R.id.lvRideDetails); 
    llNoBookings = (LinearLayout) findViewById(R.id.llNoBookings); 

    HsApi = new APIImple(); 
    onGoingRideResult = new ArrayList<OnGoingRideDetails>(); 
    mTask = new GetOnGoingRideDetails().execute(); 

    if (!(Utilities.getStringFromPrefs(getApplicationContext(), "userType") 
     .equals("driver"))) { 

     newRide.setVisibility(View.VISIBLE); 
     newRide.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if (!Utilities.isConnected(getApplicationContext())) { 
        Utilities.notConnectedToast(getApplicationContext()); 

       } else { 
        Intent in = new Intent(OnGoingRideDetailsList.this, 
         FragmentActivity.class); 
        startActivity(in); 
       } 
      } 


     }); 
    } 
    else { 
     newRide = (Button) findViewById(R.id.btnNewRide); 
     newRide.setVisibility(View.GONE); 
    } 

lvRideList.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 
      // TODO Auto-generated method stub 

      if (onGoingRideResult.get(position).getUserType() 
       .equals("driver")) { 
       Intent intentToDriverScreen = new Intent(
        OnGoingRideDetailsList.this, 
        DriverWelcomeScreen.class); 
       intentToDriverScreen.putExtra("rideData", 
        onGoingRideResult.get(position)); 
       startActivity(intentToDriverScreen); 
      } 
      else { 
       Intent intentToUserRideScreen = new Intent(
        OnGoingRideDetailsList.this, 
        UserCurrentBookings.class); 
       intentToUserRideScreen.putExtra("rideData", 
        onGoingRideResult.get(position)); 
       startActivity(intentToUserRideScreen); 
      } 
     } 
    }); 

} 

XML activity_ongoing_ride_details.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/bgcolor" 
    android:descendantFocusability="blocksDescendants"> 


<Button 
    android:id="@+id/btnNewRide" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="10dp" 
    android:background="@drawable/mybutton_bg" 
    android:clickable="true" 
    android:text="Click here for New Ride" 
    android:textColor="@color/buttontextcolor" 
    android:textSize="15dp" 
    android:visibility="visible"/> 


<ListView 
    android:id="@+id/lvRideDetails" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="#c8c8c8" 
    android:dividerHeight="1dp" 
    android:focusable="false"/> 

<LinearLayout 
    android:id="@+id/llNoBookings" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center_horizontal" 
    android:orientation="vertical" 
    android:visibility="gone"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center" 
     android:padding="10dp" 
     android:text="Sorry! No Active Bookings Available for you" 
     android:textColor="#ff9966" 
     android:textStyle="bold"/> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:src="@drawable/sadsmiley"/> 
</LinearLayout> 

</RelativeLayout> 
+0

Что именно вы подразумеваете под «не признавать»? –

+0

событие onclick не работает – HsRaja

+0

Добавить 'newRide = (кнопка) cView.findViewById (R.id.btnNewRide);' перед кодом видимости 'NewRide'. – W4R10CK

ответ

0
if (!(Utilities.getStringFromPrefs(getApplicationContext(), "userType") 
    .equals("driver"))) 

Я думаю, что проблема в этом заявлении. Это условие неверно

+0

Это не проблема, я получаю отчет о том, что..perfect – HsRaja

+0

Можете ли вы разместить свой макет ... Возможно, ваша кнопка скрыта каким-то другим видом. – WorieN

+0

Кроме того, вы объявили FragmentActivity в манифесте? – WorieN

 Смежные вопросы

  • Нет связанных вопросов^_^