2017-03-20 10 views
-1

残高などを確認するUSSDコマンドを送信するアプリケーションを構築しています アイテムのクリックからアクティビティを起動しようとすると、アプリケーションが奇妙に動作します。イメージボタンからここにアクセスする必要があります。アクティビティを開始する時間。私は何が間違っているのか分からない。アイテムの奇妙な動作

MainActivity.java:

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.ImageButton; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 


public class MainActivity extends AppCompatActivity { 

    ImageView accountView; 
    ImageView activationsView; 
    ImageView servicesView; 
    ImageView othersView; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

    } 

    public void openAccountView(View view){ 
     accountView = (ImageView) findViewById(R.id.accountView); 
     accountView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent i = new Intent(MainActivity.this, AccountActivity.class); 
       startActivity(i); 
      } 
     }); 
    } 

    public void openActivationsView(View view){ 
     activationsView = (ImageView) findViewById(R.id.activationsView); 
     activationsView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent i = new Intent(MainActivity.this, ActivationsActivity.class); 
       startActivity(i); 
      } 
     }); 
    } 

    public void openServicesView(View view){ 
     servicesView = (ImageView) findViewById(R.id.servicesView); 
     servicesView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent i = new Intent(MainActivity.this, ServicesActivity.class); 
       startActivity(i); 
      } 
     }); 
    } 

    public void openOthersView(View view){ 

    } 


} 

activity_main.xml:あなたは、このことにより、onClickのImageViewのでopenAccountViewメソッドを呼び出している

<?xml version="1.0" encoding="utf-8" ?> 
<RelativeLayout 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:id="@id/layout_dashboard_parent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:background="@color/c_dashboard_btn_quick_clean_color" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/buttonCB" 
      style="@android:style/Widget.Material.Light.Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="2dip" 
      android:layout_marginLeft="2dip" 
      android:layout_marginRight="2dip" 
      android:layout_weight="2" 
      android:background="@color/c_main_back_ground_color" 
      android:elevation="7dp" 
      android:text="@string/check_balance" 
      tools:ignore="ButtonStyle" 
      tools:targetApi="lollipop" /> 

     <Button 
      android:id="@+id/buttonLB" 
      style="@android:style/Widget.Material.Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="2dip" 
      android:layout_marginRight="2dip" 
      android:layout_marginStart="2dip" 
      android:layout_weight="2" 
      android:background="@color/c_main_back_ground_color" 
      android:elevation="7dp" 
      android:text="@string/load_balance" 
      tools:ignore="ButtonStyle" 
      tools:targetApi="lollipop" /> 
    </LinearLayout> 

    <ScrollView 
     android:id="@id/main_scroll_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/webview_ads" 
     tools:ignore="UnknownIdInLayout"> 

     <LinearLayout 
      android:id="@id/layout_dashboard_scroll_container" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <FrameLayout 
       android:id="@id/dashboard_alert_section" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:visibility="gone"> 

       <include layout="@layout/dashboard_feature_tip_item" /> 

      </FrameLayout> 

      <FrameLayout 
       android:id="@id/main_control_layout" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight="345"> 

       <FrameLayout 
        android:id="@id/dashboard_progress_bar" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginTop="@dimen/dashboard_clean_progess_mar_top" 
        android:elevation="@dimen/dashboard_progressbar_elevation" 
        android:visibility="gone" 
        tools:ignore="UselessParent" 
        tools:targetApi="lollipop"> 

        <ImageView 
         android:layout_width="@dimen/dashboard_progress_clean_all_image_dimension" 
         android:layout_height="@dimen/dashboard_progress_clean_all_image_dimension" 
         android:layout_gravity="center" 
         android:contentDescription="" 
         android:src="@drawable/btn_ram_checkbox" 
         tools:ignore="ContentDescription" /> 

        <ProgressBar 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" /> 
       </FrameLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:id="@id/layout_main" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:background="@color/c_main_back_ground_color"> 

     <RelativeLayout 
      android:id="@id/layout_account" 
      android:layout_width="@dimen/dashboard_feature_layout_width" 
      android:layout_height="@dimen/dashboard_feature_layout_height" 
      android:layout_marginEnd="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginLeft="@dimen/dashboard_feature_leftmost_margin" 
      android:layout_marginRight="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginStart="@dimen/dashboard_feature_leftmost_margin" 
      android:layout_marginTop="@dimen/dashboard_feature_top_margin" 
      android:background="@drawable/dashboard_bg_selector" 
      android:clickable="false" 
      android:elevation="6dp" 
      android:focusable="false" 
      tools:targetApi="lollipop"> 

      <ImageView 
       android:id="@+id/accountView" 
       android:layout_width="130dip" 
       android:layout_height="130dip" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:adjustViewBounds="false" 
       android:background="@color/checkbox_button_color" 
       android:clickable="true" 
       android:contentDescription="@string/account" 
       android:cropToPadding="false" 
       android:onClick="openAccountView" 
       android:visibility="visible" 
       app:srcCompat="@drawable/account" /> 

      <TextView 
       android:id="@+id/accountTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="14dp" 
       android:gravity="center_vertical|center_horizontal|center" 
       android:text="@string/account" 
       android:textColor="@color/body_text_color" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/accountView" 
       android:paddingBottom="2dip" 
       android:paddingEnd="2dip" 
       android:paddingLeft="2dip" 
       android:paddingRight="2dip" 
       android:paddingStart="2dip" 
       android:text="@string/account_detail" 
       android:textAlignment="center" 
       android:textColor="@color/black" 
       android:textSize="12sp" /> 

     </RelativeLayout> 

     <RelativeLayout 
      android:id="@id/layout_activations" 
      android:layout_width="@dimen/dashboard_feature_layout_width" 
      android:layout_height="@dimen/dashboard_feature_layout_height" 
      android:layout_marginEnd="@dimen/dashboard_feature_rightmost_margin" 
      android:layout_marginLeft="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginRight="@dimen/dashboard_feature_rightmost_margin" 
      android:layout_marginStart="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginTop="@dimen/dashboard_feature_top_margin" 
      android:layout_toEndOf="@id/layout_account" 
      android:layout_toRightOf="@id/layout_account" 
      android:background="@drawable/dashboard_bg_selector" 
      android:clickable="false" 
      android:elevation="@dimen/dashboard_feature_bg_elevation" 
      android:focusable="false" 
      android:onClick="openActivationsView" 
      tools:targetApi="lollipop"> 

      <ImageView 
       android:id="@+id/activationsView" 
       android:layout_width="130dip" 
       android:layout_height="130dip" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentTop="false" 
       android:layout_centerHorizontal="true" 
       android:layout_centerInParent="true" 
       android:layout_centerVertical="true" 
       android:clickable="true" 
       android:contentDescription="@string/activations_packs" 
       android:onClick="openActivationsView" 
       app:srcCompat="@drawable/activations" /> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/activationsView" 
       android:elevation="7dp" 
       android:paddingBottom="2dip" 
       android:paddingEnd="2dip" 
       android:paddingLeft="2dip" 
       android:paddingRight="2dip" 
       android:paddingStart="2dip" 
       android:text="@string/activations_detail" 
       android:textAlignment="center" 
       android:textColor="@color/black" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/activationsTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="14dp" 
       android:gravity="center_vertical|center_horizontal|center" 
       android:text="@string/activations_packs" 
       android:textAlignment="center" 
       android:textColor="@color/black" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

     </RelativeLayout> 

     <RelativeLayout 
      android:id="@id/layout_services" 
      android:layout_width="@dimen/dashboard_feature_layout_width" 
      android:layout_height="@dimen/dashboard_feature_layout_height" 
      android:layout_below="@id/layout_account" 
      android:layout_marginBottom="10dip" 
      android:layout_marginEnd="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginLeft="@dimen/dashboard_feature_leftmost_margin" 
      android:layout_marginRight="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginStart="@dimen/dashboard_feature_leftmost_margin" 
      android:layout_marginTop="@dimen/dashboard_feature_ram_security_top_margin" 
      android:background="@drawable/dashboard_bg_selector" 
      android:clickable="false" 
      android:elevation="5dp" 
      android:focusable="false" 
      android:onClick="openServicesView" 
      tools:targetApi="lollipop"> 

      <TextView 
       android:id="@+id/servicesTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="14dp" 
       android:gravity="center_vertical|center_horizontal|center" 
       android:text="@string/services" 
       android:textColor="@android:color/black" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

      <ImageView 
       android:id="@+id/servicesView" 
       android:layout_width="130dip" 
       android:layout_height="130dip" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:contentDescription="@string/services" 
       app:srcCompat="@drawable/services" /> 

      <TextView 
       android:id="@+id/textView5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@+id/servicesView" 
       android:paddingBottom="2dip" 
       android:paddingEnd="2dip" 
       android:paddingLeft="2dip" 
       android:paddingRight="2dip" 
       android:paddingStart="2dip" 
       android:text="@string/services_detail" 
       android:textAlignment="center" 
       android:textColor="@color/black" 
       android:textSize="12sp" /> 

     </RelativeLayout> 

     <RelativeLayout 
      android:id="@id/layout_others" 
      android:layout_width="@dimen/dashboard_feature_layout_width" 
      android:layout_height="@dimen/dashboard_feature_layout_height" 
      android:layout_below="@id/layout_activations" 
      android:layout_marginBottom="10dip" 
      android:layout_marginEnd="@dimen/dashboard_feature_rightmost_margin" 
      android:layout_marginLeft="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginRight="@dimen/dashboard_feature_rightmost_margin" 
      android:layout_marginStart="@dimen/dashboard_feature_middle_margin" 
      android:layout_marginTop="@dimen/dashboard_feature_ram_security_top_margin" 
      android:layout_toEndOf="@id/layout_services" 
      android:layout_toRightOf="@id/layout_services" 
      android:background="@drawable/dashboard_bg_selector" 
      android:clickable="false" 
      android:elevation="@dimen/dashboard_feature_bg_elevation" 
      android:focusable="false" 
      tools:targetApi="lollipop"> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="31dp" 
       android:text="@string/other_detail" 
       android:textColor="@color/black" 
       android:textSize="12sp" /> 

      <ImageView 
       android:id="@+id/otherView" 
       android:layout_width="130dip" 
       android:layout_height="130dip" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:contentDescription="@string/other" 
       app:srcCompat="@drawable/help" /> 

      <TextView 
       android:id="@+id/otherTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="14dp" 
       android:clickable="true" 
       android:gravity="center_vertical|center_horizontal|center" 
       android:onClick="openOthersView" 
       android:text="@string/other" 
       android:textColor="@color/black" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

     </RelativeLayout> 

    </RelativeLayout> 


</RelativeLayout> 

答えて

2

は、私のコードを見てください

android:onClick="openAccountView"

あなたのimageViewにonClicklistenerを追加する必要はありません。

openAccountViewonClicklistenerを削除し、以下のコードを使用します

public void openAccountView(View view){ 
      Intent i = new Intent(MainActivity.this, AccountActivity.class); 
      startActivity(i); 
    } 

・ホープ、このことができますし。

+0

ありがとう、それは動作します!私は何を間違っていたのですか? –

+0

あなたは既にxmlからonClickを通してインテントを呼び出しています。また、アクティビティのimageViewにonClickListenerを追加することで、インテントを呼び出すために2回クリックする必要があります。このことを明確にすることを願っています。 – tahsinRupam

+0

エキスパートが一度ノブだったとしても心配しないでください! – tahsinRupam