单击listview项后如何显示位图图像

时间:2012-07-23 07:04:37

标签: android bitmap

我对android编程很新。我正在开发我的第一个应用程序。

我正在尝试在res / drawable-mdpi中显示保存在前一个活动中列表视图的短文本下面的图像。例如,点击时有一个带有电视节目名称的列表视图将具有电视节目的名称,后面跟着该电视节目的图像。我尝试了很多不同的东西,但这里是我正在使用的基本代码。文本加载它但我想要下面的图像。

package com.example.listviews;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class LocationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Get the message from the intent
    Intent intent = getIntent();
    String message = intent.getStringExtra("valueLoc");

    // Create the text view
    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

   //     ImageView image = (ImageView) findViewById(R.id.menu_settings);

    setContentView(textView);
}
}

1 个答案:

答案 0 :(得分:1)

你应该建立一个列表视图:

//Initialize the programs array
String[]  programsArray = new String[10];

... /* Fill programsArray */

listView = ( ListView ) findViewById( R.id.programlistview );
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, programArray);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {             
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        /* Code to show image */        
    }
});

我无法建议您显示图像的任何代码,因为此部分的问题过于笼统,代码取决于您希望如何显示图像。您可以使用Popup,其他活动,同一活动中的框架等。

相关问题