尝试弹出窗口时感到困惑

时间:2013-06-19 06:02:43

标签: android popup

当客户从列表项中选择一个项目时,我想显示弹出窗口。现在我的代码就像这样,当我点击一个项目时,它会指向显示下载链接的新布局。
我想问的是,如何让我的DownloadText类成为弹出窗口?所以客户端可以看到链接而无需移动到其他布局?
任何人,请帮我怎么做。非常感谢你

DownloadDetail.java - 这个用于显示列表项

public class DownloadDetail extends ListActivity {
public Koneksi linkurl;

    String SERVER_URL;
    private RSSFeed myRssFeed = null;

    public class MyCustomAdapter extends ArrayAdapter<RSSItem> {

        public MyCustomAdapter(Context context, int textViewResourceId,
                List<RSSItem> list) {
            super(context, textViewResourceId, list);   
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            //return super.getView(position, convertView, parent);

            View row = convertView;

            if(row==null){
                LayoutInflater inflater=getLayoutInflater();
                row=inflater.inflate(R.layout.rss_row, parent, false);  
            }

            TextView listTitle=(TextView)row.findViewById(R.id.juduldl);
            listTitle.setText(myRssFeed.getList().get(position).getTitle());
            /*TextView listPubdate=(TextView)row.findViewById(R.id.status);
            listPubdate.setText(myRssFeed.getList().get(position).getPubdate());*/

            return row;
        }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rss);

        Bundle bundle = this.getIntent().getExtras();

        String param1 = bundle.getString("keyIdc");
        String param2 = bundle.getString("keyUserId");


        SERVER_URL = SERVER_URL+"?idc="+param1+"&un="+param2;
        try {
            linkurl = new Koneksi(this);
            SERVER_URL = linkurl.getUrl();
            SERVER_URL += "/mobile/DownloadDetail.php?idc="+param1+"&idu="+param2;
            URL rssUrl = new URL(SERVER_URL);
            SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
            SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
            XMLReader myXMLReader = mySAXParser.getXMLReader();
            RSSHandler myRSSHandler = new RSSHandler();
            myXMLReader.setContentHandler(myRSSHandler);
            InputSource myInputSource = new InputSource(rssUrl.openStream());
            myXMLReader.parse(myInputSource);

            myRssFeed = myRSSHandler.getFeed();

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        if (myRssFeed!=null)
        {
            TextView feedTitle = (TextView)findViewById(R.id.feedtitle);
            TextView feedDescribtion = (TextView)findViewById(R.id.feeddescription);
            TextView feedPubdate = (TextView)findViewById(R.id.feedPubdate);
            TextView feedLink = (TextView)findViewById(R.id.feedlink);
            feedTitle.setText(myRssFeed.getTitle());
            feedDescribtion.setText(myRssFeed.getDescription());
            feedPubdate.setText(myRssFeed.getPubdate());
            feedLink.setText(myRssFeed.getLink());

            /*ArrayAdapter<RSSItem> adapter = 
                new ArrayAdapter<RSSItem>(this,
                        android.R.layout.simple_list_item_1,myRssFeed.getList());
            setListAdapter(adapter);*/
            MyCustomAdapter adapter =
                    new MyCustomAdapter(this, R.layout.rss_row, myRssFeed.getList());
                setListAdapter(adapter);
        }
    }


    protected void onListItemClick(ListView l, View v, int position, long id) {

        Intent intent = new Intent(this,DownloadText.class);
        Bundle bundle = new Bundle();
        bundle.putString("keyNama", myRssFeed.getItem(position).getTitle());
        bundle.putString("keyReference", myRssFeed.getItem(position).getDescription());
        bundle.putString("keyIdc", myRssFeed.getItem(position).getLink());
        intent.putExtras(bundle);
        startActivity(intent);
    }
}

DownloadText.java - 此代码显示链接

public class DownloadText extends Activity{
    public Koneksi linkurl;
    public Kondownload linkurl2;
    String url;
    String SERVER_URL;
    String SERVER_URL2;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.linkdownload);

        TextView mTextLink = (TextView) findViewById(R.id.LinkDownload);
        Bundle bundle = this.getIntent().getExtras();

        String param1 = bundle.getString("keyIdc");
        String param2 = bundle.getString("keyReference");
        if(param2.endsWith(".pdf"))
        {
            linkurl = new Koneksi(this);
            SERVER_URL = linkurl.getUrl();
            SERVER_URL += "/moodledata/"+param1+"/"+param2;
            mTextLink.setText(SERVER_URL);
            Pattern pattern = Pattern.compile(SERVER_URL);
           Linkify.addLinks(mTextLink, pattern, "");

        }
        else
        {
            linkurl2 = new Kondownload(param2);
            SERVER_URL2 = linkurl2.getUrl();
            mTextLink.setText(SERVER_URL2);
            Pattern pattern = Pattern.compile(SERVER_URL2);
           Linkify.addLinks(mTextLink, pattern, "");
        }

    }
}

linkdownload.xml

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/AbsoluteLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    tools:ignore="Deprecated" >

    <TextView
        android:id="@+id/Text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="6dip"
        android:layout_y="9dip"
        android:gravity="center"
        android:text="@string/silahkan_klik_link_di_bawah_ini_untuk_mengunduh_file"
        android:textColor="#000000"
        android:textSize="20dp"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:id="@+id/LinkDownload"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="6dip"
        android:layout_y="133dip"
        android:text="@string/ld" >
    </TextView>

</AbsoluteLayout>

2 个答案:

答案 0 :(得分:0)

您可以将布局设置为对话框窗口。

    Dialog listDialog = new Dialog(activity);

            LayoutInflater li = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = li.inflate(R.layout.popover, null, false);
            listDialog.setContentView(v);
listDialog.show();

答案 1 :(得分:0)

我猜你知道System.out.println();是否以及如何检查?

替换:

protected void onListItemClick(ListView l, View v, int position, long id) {
        System.out.println("item clicked!");
        Intent intent = new Intent(this,DownloadText.class);
        Bundle bundle = new Bundle();
        bundle.putString("keyNama", myRssFeed.getItem(position).getTitle());
        bundle.putString("keyReference", myRssFeed.getItem(position).getDescription());
        bundle.putString("keyIdc", myRssFeed.getItem(position).getLink());
        intent.putExtras(bundle);
        startActivity(intent);
    }

使用:

protected void onListItemClick(ListView l, View v, int position, long id) {

        public Koneksi linkurl;
        public Kondownload linkurl2;
        String url;
        String SERVER_URL;
        String SERVER_URL2;
        String str_keyNama = null;
        String str_keyReference = null;
        String str_keyIdc = null;
        String str_link = null;


        str_keyNama =("keyNama", myRssFeed.getItem(position).getTitle().toString());
        str_keyReference =("keyReference", myRssFeed.getItem(position).getDescription().toString());
        str_keyIdc =("keyIdc", myRssFeed.getItem(position).getLink().toString());


        String param1 =  str_keyIdc;
        String param2 = str_keyReference;
        if(param2.endsWith(".pdf"))
        {
            linkurl = new Koneksi(this);
            SERVER_URL = linkurl.getUrl();
            SERVER_URL += "/moodledata/"+param1+"/"+param2;
            str_link = SERVER_URL.toString();
            System.out.println("SERVER_URL = "+str_link);
            //Pattern pattern = Pattern.compile(SERVER_URL);
            //Linkify.addLinks(mTextLink, pattern, "");

        }
        else
        {
            linkurl2 = new Kondownload(param2);
            SERVER_URL2 = linkurl2.getUrl();
            str_link = SERVER_URL2.toString();
            System.out.println("SERVER_URL2 = "+str_link);
           //Pattern pattern = Pattern.compile(SERVER_URL2);
           //Linkify.addLinks(mTextLink, pattern, "");
        }


    }