我用Adroid Studio 3.0编写了一个简单的APP(通过基本活动模板): 在" content_main"布局,只有" EditText" Feature1:当我点击" EditText"时,将显示IME 并且还将显示ListPopupWindow以及字符串列表。 Feature2:此时,我可以继续输入EditText,同时显示ListPopupWindow。 Feature3:我可以滚动ListPopupWindow并单击一个项目, 然后该项目将在EditText中显示,ListPopupWindow将被解除。
我的问题是:
Running on Android 7.0, I can select one item in the ListPopupWindow.
But on Android 4.2, the items in ListPopupWindow can not be clicked.
我的分析: 如果我变为:listPopupWindow.setModal(true), Feature2无法实现。
以下是关键源代码:
MainActivity extends AppCompatActivity implements OnItemClickListener {
EditText productName;
ListPopupWindow listPopupWindow;
String[] products={"Camera", "Laptop", "Watch","Smartphone", "Television"};
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
productName.setText(products[position]);
listPopupWindow.dismiss();
}
protected void onCreate(Bundle savedInstanceState) {
...
productName = (EditText) findViewById(R.id.product_name);
listPopupWindow = new ListPopupWindow(MainActivity.this);
listPopupWindow.setAdapter(new ArrayAdapter(
MainActivity.this,
R.layout.list_item, products));
listPopupWindow.setAnchorView(productName);
listPopupWindow.setModal(false);
listPopupWindow.setOnItemClickListener(
MainActivity.this);
productName.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
listPopupWindow.show();
}
});
}
}
答案 0 :(得分:0)
您可以使用<?php
$folder_path='c:/wwwroot/content/stack';
/* find all files in chosen folder */
$col=glob( $folder_path . '\*.*' );
/* filter only text files for processing */
$col=preg_grep( '@(\.txt$)@i', $col );
/* Proceed if there are text files only */
if( !empty( $col ) && count( $col ) > 0 ){
/* iterate through collection */
foreach( $col as $index => $filepath ){
/* read file contents into an array */
$lines=file( $filepath );
/* store altered lines in temp array */
$content=array();
/* trim the start of each line & store into temp array */
foreach( $lines as $line )if( !empty( $line ) ) $content[]=ltrim( $line );
/* output file contents */
file_put_contents( $filepath, implode( PHP_EOL, $content ) );
echo file_get_contents( $filepath ) . PHP_EOL . PHP_EOL;
}
printf( "finito! %d files processed",count( $col ) );
} else {
echo "nothing to process";
}
?>
代替普通AutoCompleteTextView
,而无需使用EditText
,自动填充将执行您需要的任务,因为您希望在撰写时向用户显示建议一些东西。这里是
Reference