当前位置: 首页 > news >正文

django做的购物网站百度如何购买关键词

django做的购物网站,百度如何购买关键词,wordpress 模板调用函数,网站还没上线怎么做品牌推广最近项目原因,需要做出一个类似baidu搜索时下拉框的效果如图 于是乎想了多种办法,一种是利用AutoCompleteTextViewListView方式,但是这种方式有一个缺点就是需要用帧布局,同时在利用AutoCompleteTextView.addTextChangedListener方…

最近项目原因,需要做出一个类似baidu搜索时下拉框的效果如图

于是乎想了多种办法,一种是利用AutoCompleteTextView+ListView方式,但是这种方式有一个缺点就是需要用帧布局,同时在利用AutoCompleteTextView.addTextChangedListener方法控制ListView的显示和消失时遇到一个很大的问题就是无法让其消失,即使你选中了一个条目,因为TextChanged的原因,ListView也是以一条你选中的条目为显示内容的形式在AutoCompleteTextView的下方,没有找到好的解决办法。

之所以想到以上这种办法的原因是在项目的一开始没有使用AutoCompleteTextView的原生态的下拉列表(有各种各样的不更新造成的),后来在使用AutoCompleteTextView+ListView无效的情况下只能回到AutoCompleteTextView的原生态的下拉列表的方法上。

http://stackoverflow.com/tags/autocompletetextview/hot这是stackoverflow上关于AutoCompleteTextView的FAQ,从中我们可以看到有多个关于从网上获取条目然后显示在AutoCompleteTextView的列表之上的问题和相应的回答。最终选中了http://stackoverflow.com/questions/8653260/autocomplete-in-android-not-working-with-dynamic-data这个问题当中名为iNan的解答,并对其进行了改进。

具体代码如下

WikiSuggestActivity

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
/*** @Title: WikiSuggestActivity.java* @Package com.yang.testautocompletetextview* @Description: 参考http://stackoverflow.com/questions/8653260/autocomplete-in-android-not-working-with-dynamic-data* @author Yang  * @date 2012-8-12 下午2:59:54* @version V1.0*/
public class WikiSuggestActivity extends Activity {public String data;public List<String> suggest;public AutoCompleteTextView autoComplete;public ArrayAdapter<String> aAdapter;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);suggest = new ArrayList<String>();autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);autoComplete.addTextChangedListener(new TextWatcher(){public void afterTextChanged(Editable editable) {}public void beforeTextChanged(CharSequence s, int start, int count, int after) {}public void onTextChanged(CharSequence s, int start, int before, int count) {String newText = s.toString();new getJson().execute(newText);}});}class getJson extends AsyncTask<String,String,String>{@Overrideprotected void onPostExecute(String result) {super.onPostExecute(result);aAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.item,suggest);autoComplete.setAdapter(aAdapter);aAdapter.notifyDataSetChanged();}@Overrideprotected String doInBackground(String... key) {String newText = key[0];newText = newText.trim();newText = newText.replace(" ", "+");try{HttpClient hClient = new DefaultHttpClient();HttpGet hGet = new HttpGet("http://en.wikipedia.org/w/api.php?action=opensearch&search="+newText+"&limit=8&namespace=0&format=json");ResponseHandler<String> rHandler = new BasicResponseHandler();data = hClient.execute(hGet,rHandler);suggest = new ArrayList<String>();JSONArray jArray = new JSONArray(data);for(int i=0;i<jArray.getJSONArray(1).length();i++){String SuggestKey = jArray.getJSONArray(1).getString(i);suggest.add(SuggestKey);}}catch(Exception e){Log.w("Error", e.getMessage());}return null;}}
}
activity_main.xml

<RelativeLayout 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" ><AutoCompleteTextViewandroid:id="@+id/autoCompleteTextView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:ems="10" /><!-- android:ems  设置TextView的宽度为N个字符的宽度。这里测试为一个汉字字符宽度 --></RelativeLayout>
item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"  
android:id="@+id/online_user_list_item_textview" >
</TextView>
效果图如下:



整个项目代码下载地址


http://www.wooajung.com/news/35055.html

相关文章:

  • 幼儿园网站建设7个基本流程百度大搜数据多少钱一条
  • 望牛墩网站仿做腾讯广告推广怎么做
  • 网站 app 哪个先做网站推广的100种方法
  • 大连做网站外包电话营销话术
  • 学做立体书的网站深圳网络推广怎么做
  • 苏州网站快速推广宁波seo网络推广优化价格
  • 免费建设网站公司哪家好刷排名seo
  • 福州最好的网站建设关键词推广系统
  • 网站建设的基本原则seo社区
  • 推广一个网站需要什么今日国际新闻头条15条
  • 专业的论坛网站建设开发燃灯seo
  • 徐州市专业做网站的公司企业网站推广
  • 艺麟盛世可以做网站推广吗seo 优化公司
  • 天津网站的优化最新国际新闻热点事件
  • html做的旅游网站搜索引擎广告形式有哪些
  • 运维网站建设爱站网seo培训
  • 全国知名十大计算机培训学校seo推广软件代理
  • 青岛手机网站设计公司seo知识是什么意思
  • 免费拓客软件排行榜河北seo网络优化师
  • 头像制作软件app汕头seo托管
  • 专业企业网站建设公司google seo实战教程
  • 怎么在地图上设置自己店的位置马鞍山网站seo
  • 做网站的客户需求搭建网站
  • 东营网站制作公司近三天新闻50字左右
  • 设计网站建网站关键词优化软件
  • 怎么通过做网站挣钱重庆网站推广联系方式
  • 建设自己的网站关键词优化如何
  • 自己的卡盟网站怎么做分站长沙网络推广营销
  • 淘宝运营工作内容廊坊网站排名优化公司哪家好
  • 企业内部网站建设费用上海seo优化公司 kinglink