Возможно ли иметь два TextViews в маркере гистограммы? - PullRequest
0 голосов
/ 19 сентября 2019

Я создаю диаграмму, используя MpAndroidChart и используя собственный маркер.У меня есть два TextViews внутри маркера, но только один из них отображает данные.Первый - единственный, отображающий данные.Однако, если я помещаю точку останова в переопределение getOffset (), а затем оцениваю выражение tvDateTime.getText (), текст устанавливается там во втором TextView.


public class MyMarkerView extends MarkerView {

    private TextView tvSensorData, tvDateTime;

    private ArrayList<String[]> tooltipTxtsArr;

    public MyMarkerView(Context context, int layoutResource, ArrayList<String[]> tooltipTxt) {
        super(context, layoutResource);

        // this markerview only displays a textview
        tvSensorData = findViewById(R.id.sensorData);
        tvDateTime = findViewById(R.id.dateTime);

        tooltipTxtsArr = tooltipTxt;
    }


    // callbacks every time the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        //TODO:
        // set the entry-value as the display text
        Integer ix = (int) e.getX();
        String[] textData = tooltipTxtsArr.get(ix);
        tvSensorData.setText(textData[0]);
        tvDateTime.setText(textData[1]);
    }


    private MPPointF mOffset;

    @Override
    public MPPointF getOffset() {

        if (mOffset == null) {
            int markerH = getHeight();
            int markerW = getWidth();

            // center the marker horizontally
            mOffset = new MPPointF(-(markerW/ 2), -(markerH));
        }

        return mOffset;
    }

}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="121dp"
    android:layout_height="80dp"
    android:background="@drawable/marker_background_gray"
    android:padding="7dp"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="21dp"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/sensorData"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:text=""
            android:textSize="12dp"
            android:textColor="#444444"
            android:textStyle="bold"
            android:layout_gravity="center_horizontal"
            android:ellipsize="end"
            android:singleLine="true"
             />

        <TextView
            android:id="@+id/dateTime"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text=""
            android:textSize="12dp"
            android:textColor="#444444"
            android:ellipsize="end"
            android:singleLine="false"
             />

    </LinearLayout>

</RelativeLayout>



...