我有一个arraylist<interface>
对象被添加到for循环中的列表中.每次调用方法时,我都希望这个arraylist为空.
这是代码:
我想在这里清空的数组是建议的Phrases.
public List<Interface> returnSuggestedList(String prefix) {
String tempPrefix = prefix;
// suggestedPhrases = null;
//suggestedPhrases = new ArrayList<Interface>();
//Vector<String> list = new Vector<String>();
//List<Interface> interfaceList = new ArrayList<Interface>();
Collections.sort(wordsList);
System.out.println("Sorted Vector contains : " + wordsList);
int i = 0;
//List<String> selected = new ArrayList<String>();
for(String w:wordsList){
System.out.println(w);
if(w.startsWith(prefix.toLowerCase())) { // or .contains(), depending on
//selected.add(w); // what you want exactly
Item itemInt = new Item(w);
suggestedPhrases.add(itemInt);
}
}
Run Code Online (Sandbox Code Playgroud) 我只想尝试以下格式的简单JSON数组:["Country1","Country2","Country3"]来自网络,然后在我的Android应用程序中将该数组用作列表视图.我并没有停留在如何制作这个JSON数组,我只是对如何将它放入应用程序中的列表视图感到困惑.
我尝试过几个不同的教程,但没有一个使用与我相同的布局.
我的应用程序正在使用viewflipper,以便在整个应用程序中始终保持基于标签的布局,因此没有任何教程似乎使用我的布局.
任何帮助深表感谢.
编辑:
这是一些代码,是的,我想从Web服务解析它并将其显示在列表视图中.
public class Activity extends TabActivity implements OnClickListener {
Button doSomething;
TabHost tabHost;
ViewFlipper flipper;
ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tablayout_1);
doSomething = (Button) findViewById(R.id.btn_do_something);
doSomething.setOnClickListener(this);
flipper = (ViewFlipper) findViewById(R.id.layout_tab_one);
listview = (ListView) findViewById(R.id.listview);
@SuppressWarnings("unchecked")
ListAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,fetchTwitterPublicTimeline());
//ListAdapter adapter = new SimpleAdapter(this, this.fetchTwitterPublicTimeline() , R.layout.main, new int[] { R.id.item_title, R.id.item_subtitle });
listview.setAdapter(adapter);
flipper.setOnClickListener(this);
String tabname1 = getString(R.string.tabexample_tab1);
String tabname2 = getString(R.string.tabexample_tab2);
String tabname3 = getString(R.string.tabexample_tab3);
String tabname4 = …Run Code Online (Sandbox Code Playgroud) 我的网页上有以下代码 - 地图div没有显示谷歌地图,但我发现代码没有任何问题:
$mapCode = "<script src=\"http://maps.google.com/maps?file=api&v=2&sensor=false&key=$google_maps_apiKey\" type=\"text/javascript\"></script>
<div id=\"map_canvas\" style=\"width: 500px; height: 500px\"></div>
<script type=\"text/javascript\">
function showAddress(address) {
var map = new GMap2(document.getElementById('map_canvas'));
alert(\" not found\");
var geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + \" not found\");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
showAddress(\"$address\");
</script>";
echo $mapCode;
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢.谢谢
我想使用以下代码:
List<ItemInterface> interfaceList = new List<ItemInterface>();
Run Code Online (Sandbox Code Playgroud)
Eclipse给出错误:无法实例化类型List
这段代码有什么问题?
我有一张桌子上有一份商家名单.每行都有详细信息,例如商家名称,ID,区域,数字等等.
我正在查询mysql数据库,目前我只检索商家名称和ID.然后我使用json_encode函数获得如下输出:{"BusinessA":"business_A_ID","BusinessB":"business_B_ID"}
我希望能够检索所有业务细节并使用json编码函数来获得如下输出:
[
{
"businessName": "BusinessA",
"businessID": "business_A_ID"
},
{
"businessName": "BusinessB",
"businessID": "businees_B_ID"
}
]
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的当前代码:
$businessRow = array();
$businessResult = mysql_query("SELECT * FROM businessTable");
while($row = mysql_fetch_assoc($businessResult)) {
$businessRow[$row['businessName']] = $row['businessID'];
}
$result = json_encode($businessRow);
echo $result;
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我需要将此行更改为:
$businessRow[$row['businessName']] = $row['businessID'];
Run Code Online (Sandbox Code Playgroud)
为了获得上面的JSON输出?
谢谢