最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】实现安卓版的DownloadSongtasteMusic中的响应按钮点击

Android crifan 2239浏览 0评论

对于安卓版的DownloadSongtasteMusic,之前已经实现了,显示一个文本输入框和一个按钮:

【记录】实现安卓版的DownloadSongtasteMusic中的添加文本标签和文本输入框

现在接着去折腾,然后响应按钮点击,去执行对应的动作。


1.继续参考教程:

Respond to the Send Button

去实现响应按钮点击。

2.然后最后写出代码:

res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity" >

    <!-- 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
 	-->
 	
 	<EditText 
 	    android:id="@+id/url_or_id"
 	    android:layout_width="0dp"
 	    android:layout_height="wrap_content"
 	    android:hint="@string/url_or_id"
 	    android:layout_weight="1" />"
    
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_download"
        android:onClick="preformDownload"
        />

</LinearLayout>

 

preformDownload的具体实现:

src/crifan/com/downloadsongtastemusic/MainActivity.java

package crifan.com.downloadsongtastemusic;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    /** Called when the user clicks the Download button */
    public void preformDownload(View view) {
        // Do something in response to button
    	
    	EditText etUrlOrId = (EditText) findViewById(R.id.url_or_id);
    	String strUrlOrId = etUrlOrId.getText().toString();
    }
}

3. 然后后来去调试:

【记录】如何在ADT中调试Android程序

就可以获得了对应的变量了:

found input id value

 

4.接下来,就是去写代码。

去实现对于生成url,然后url地址的解析了。

转载请注明:在路上 » 【记录】实现安卓版的DownloadSongtasteMusic中的响应按钮点击

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.167 seconds, using 22.13MB memory