【问题标题】:Calling AlertDialog from MPAndrioid RadarChart从 MPAndrioid RadarChart 调用 AlertDialog
【发布时间】:2016-07-11 08:43:31
【问题描述】:

我可以让 RadarChart 处理一些静态数据。现在我想在用户点击雷达图时显示一个警告对话框,要求用户输入一些数据,然后使用这些输入数据重绘图表。

我创建了一个扩展 MarkerView 的 MyMarkerView 类,并在 refreshContent 方法中添加了警报对话框视图的代码。

但问题是,每当使用单击 AlerDialog 时,都会再次调用 refreshContent 并创建一个新的警报对话框 - 并且用户无法输入任何内容。 下面是 refreshContent 方法中的代码

       LayoutInflater li = LayoutInflater.from(mContext);
            View promptsView = li.inflate(R.layout.month_target_analysis_dialog, null);

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);

            final EditText userInput1 = (EditText) promptsView.findViewById(R.id.textView1Edit);
            final EditText userInput2 = (EditText) promptsView.findViewById(R.id.textView2Edit);

            // set dialog message
            alertDialogBuilder.setCancelable(false);
            alertDialogBuilder.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // get user input and set it to result
                            // edit text
                            //result.setText(userInput.getText());
                            String input1 = userInput1.getText().toString();
                            String input2 = userInput1.getText().toString();
                            if (userInput1.getError() == null && userInput2.getError() == null) {
                                //Do something
                            } else {
                            }
                        }
                    });
            alertDialogBuilder.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }

下面是 Xml 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="10dp"
            android:text="@string/l_target"
            android:textAppearance="@style/ItemMedium" />

        <EditText
            android:id="@+id/textView1Edit"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:paddingLeft="50dp"
            android:clickable="false"
            android:inputType="number"
            >
            <requestFocus />
        </EditText>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="10dp"
            android:text="@string/g_target"
            android:textAppearance="@style/ItemMedium" />

        <EditText
            android:id="@+id/textView2Edit"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:paddingLeft="50dp"
            android:clickable="false"
            android:inputType="number"
            >
        </EditText>
    </LinearLayout>

任何想法如何禁用 refreshContent 的调用? 或者有没有其他更好的处理方式?

谢谢 普拉文

【问题讨论】:

    标签: android android-alertdialog mpandroidchart


    【解决方案1】:

    我无法使用 MarkerView 使其工作。相反,我定义了一个 setOnChartGestureListener 来捕捉图表上所有可能的动作,然后在捕捉到动作时处理必要的动作。 似乎工作正常。

     mChart.setOnChartGestureListener(new OnChartGestureListener() {
           @Override
                public void onChartSingleTapped(MotionEvent me) {
                    // TODO Auto-generated method stub
                    Log.e(LOG_TAG, "single tap");
    
                }
              @Override
                public void onChartDoubleTapped(MotionEvent me) {
                    // TODO Auto-generated method stub
                    Log.e(LOG_TAG, "double tap");
                }
    }
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多