Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
795 views
in Technique[技术] by (71.8m points)

android - how to put add code that when the text(textview) is clicked, an image will appear(function like an alert dialog) .?

Questions.java

    public void onClick(View v) {  

            if (q1.isChecked()) {
                int count = 0;
                for (CheckBox cb : cbList) {
                    if (cb.isChecked()) {
                        count++;
                    }
                }           
                if (count <= 1) {
                    new AlertDialog.Builder(this).setMessage(R.string.negative).show(); 
                } else {
                    new AlertDialog.Builder(this).setMessage(R.string.positive).show(); 
                }
            }

        }

question.xml

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/q1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/sas1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/sas1"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#000000"
                android:textSize="15sp"
                android:textStyle="bold" />
        </LinearLayout>

note: never mind the checkbox

how to put add code that when the text(textview) is clicked, an image will appear( like an alert dialog) something like that.?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With a custom AlertDialog

@Override
public void onClick(View arg0) {

    // custom dialog
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.my_own_custom_dialog);
    dialog.setTitle("The Title...");

    // set the custom dialog components
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.my_own_image_resource);

    ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...