好的我有一个多选ListView工作正常.我检查联系人的框(保存在String []中)并可以返回值.因为有些人有一堆联系我想创建一个搜索栏,有点像Android手机书的库存.我创建了一个EditText并将其对齐在我的列表上方.我在StackOverflow上找到了过滤代码,它运行得非常好.
我的问题:
当您过滤某些人的名字,并选择名称时,当您从EditText退格或继续键入时,不会保存您选择的名称的正确位置.例如,如果我开始键入"Adam"并进入"Ada"并选择它,如果我退格键入"Carol",则选择"Ada"所处的位置.它收集了"亚当"在点击时所处的位置(比方说2),当列表恢复时,检查位置(2),即使亚当不在那里.我需要一种方法来收集名称..然后当再次恢复或搜索列表时,将检查NAME Adam,而不是之前的位置亚当.除了创建大量数组之外,我绝对没有任何想法,并且可以真正使用一些帮助.下面是我正在使用的一些代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_list);
myListView = (ListView)findViewById(android.R.id.list);
search_EditText = (EditText) findViewById(R.id.search_EditText);
search_EditText.addTextChangedListener(filterTextWatcher);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, ContactsList);
setListAdapter(adapter);
myListView.setItemsCanFocus(false);
getListView().setChoiceMode(2);
myListView.setTextFilterEnabled(true);
myListView.setFastScrollEnabled(true);
myListView.invalidate();
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
}
};
Run Code Online (Sandbox Code Playgroud) android android-searchmanager multiple-choice android-listview
我正在尝试使用多选项创建AlertDialog.我试过了,setMultiChoiceItems但我拥有的是一个ArrayList<Category>而不是CharSequence我尝试使用适配器.
问题setAdapter是,当我选择一个项目时,它会关闭对话框窗口.我想要的是选择项目,然后点击确定按钮,看看哪些项目被选中.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
ArrayAdapter<Category> catsAdapter = new ArrayAdapter<Category>(this, android.R.layout.select_dialog_multichoice,this.categories);
builder.setAdapter(catsAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do something
}
});;
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) android android-arrayadapter multiple-choice android-alertdialog
任何人都可以检查此代码,让我知道什么是错的?
input_list = ["One", "Two", "Three"]
P1 = input("Select the input: ", input_list[0], input_list[1], input_list[2])
print (P1)
Run Code Online (Sandbox Code Playgroud) 我正在开发一个用CMake构建的项目,所以我正在CMakeLists.txt为它编写一个.在这个文件中,我想要一个(缓存的)CMake变量,它只能采用几个选项之一(我会以某种方式指定),而不是任意字符串.为简单起见,让我们把它变成一个可以采用"红色","绿色"或"蓝色"的字符串 - 但没有别的.
我可以使用最近的CMake版本来实现这一点,除了设置任意字符串然后检查其有效性吗?
我创建了一个脚本,它将图像添加到 Google 表单以生成多项选择测验。
目前它添加了一个图像,然后添加了选项(A、B、C、D)。图像和选项是两个独立的项目。因此,我无法随机排列顺序,因为我需要确保图像和问题保持在一起。
手动创建测验允许选择添加带有问题的图像,使其显示为一个项目。这将是可取的,因为它可以让我随机化问题顺序。
我查看了 Forms Service API,但看不到将图像添加到多项选择题的选项。是否有可能的解决方案(除了手工操作?)
发现这个问题有一个非常相似的问题,但没有回复: Google Script: Add an image to a Google Form item (不同于 ImageItem)
在模型中有多种选择,我有两个不同的问题.
首先,我正在尝试进行多项选择,以便用户可以选择一周中的一天或多天:
DAYS_CHOICES = (
(1, _('Monday')),
...
(7, _('Sunday')),
)
...
day = models.ManyToManyField('day', choices=DAYS_CHOICES)
Run Code Online (Sandbox Code Playgroud)
第二个问题:
我想在其他模型中使用模型定义创建ManyToMany Relation:First(导入模型):
from events.models import Category
Run Code Online (Sandbox Code Playgroud)
第二个(与模型相关的字段):
type = models.ManyToManyField('Category', null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
我在syncdb上收到此错误:
错误:一个或多个模型未验证:situ.situ:'day'与模型日有一个m2m关系,它没有安装或是抽象的.
situ.situ:'type'与模型类别有m2m关系,它没有安装或是抽象的.
我是python和编程的新手,所以如果这是一个"noob问题",我很抱歉.无论如何,是否可以在python中选择多项选择,而不使用if循环?
愚蠢的例子:
print "Do you want to enter the door"
raw_input ("Yes or not")
Run Code Online (Sandbox Code Playgroud)
并且用户只能在选择之间进行选择.
我试图在LaTeX中提出一个多项选择题.我是否有点困惑
\begin{question}{MultipleChoice}
是默认情况下LaTeX可以处理的东西,还是我需要额外的包,描述等...(我是LaTex的新手).
话虽如此,如果我运行以下代码,我不会得到一个多选题,而是一个错误,说'lonely\item - 可能缺少一个列表环境.
提前感谢您的时间和耐心!
%%%% ENVIRONMENT FOR LIST FOR QUESTIONS LIST %%%%
\newenvironment{questions}{ % %%%% Begin preliminary environment code
\begin{list}{ % %%%% Begin list item label code
\bfseries\upshape\arabic{qcounter}:
}{ % %%%% Begin list item body code
\usecounter{qcounter}
\setlength{\labelwidth}{1in}
\setlength{\leftmargin}{0.25in}
\setlength{\labelsep}{0.5ex}
\setlength{\itemsep}{2em}
} %%%%% End list item body code
}{ %%%%% Begin wrapup environment code
\end{list}
} %%%%% End wrapup environment code
%%%% ENVIRONMENT FOR A SINGLE QUESTION %%%%
\newenvironment{question}{\item{}}{}
\begin{question}{MultipleChoice}
\qutext{$3\log x-2\log y=$}
\choice*{$\log\left(\displaystyle\frac{x^3}{y^2}\right)$}
\choice{$\log(x^3y^2)$}
\choice{$\log(3x-2y)$} …Run Code Online (Sandbox Code Playgroud) 我需要创建一个包含多项选项的AlertDialog,但是我在尝试将自定义布局文件设置为内部ListView时遇到了一些麻烦.
对于单选项,我使用一个构造函数,它将ListAdapter作为参数,这样我就可以为每一行设置合适的布局资源:
builder.setSingleChoiceItems(new ArrayAdapter<String>(getActivity(),
R.layout.list_item_single_choice_answer, items), checkedItem,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
checkedItem = which;
toggleEditTextAnswer(checkedItem == (items.length - 1));
dialog.dismiss();
}
});
Run Code Online (Sandbox Code Playgroud)
问题是setMultiChoiceItems没有构造函数在创建多选列表时接受ListAdapter作为参数.
我需要为每一行设置一个自定义布局,因为我使用drawable选择器来设置行背景和文本颜色.
有任何想法吗?
PS.这里是AlertDialog源代码以获取更多信息. https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/app/AlertDialog.java
如何实现命令行中的多项选择参数?会有一组预定义的选项,用户可以选择多个:
python cli.py --alphabet upper,lower,digits,symbols
Run Code Online (Sandbox Code Playgroud)
或者
python cli.py --alphabet upper lower digits symbols
Run Code Online (Sandbox Code Playgroud)