我在Android中使用CheckBox视图.我想在检查时更改它的颜色.现在它是默认的深绿色,当它被检查时,我想把它改成不同的东西,当没有检查时,只是默认颜色.
这是我的代码:
CheckBox c = new CheckBox(this);
c.setId(View.generateViewId());
c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked())
{
buttonView.setBackgroundColor(Color.rgb(64, 131, 207));
}
if(!buttonView.isChecked())
{
buttonView.setBackgroundColor(Color.WHITE);
}
}
});
Run Code Online (Sandbox Code Playgroud)
问题是它没有改变正确的事情.关于如何改变这种颜色的任何想法?
我试图使用ArrayList来存储可变数量的字符串,并想知道如何保存ArrayList及其元素,以便我的窗体可以在程序加载和退出之间调用它们的值.
我曾经将信息存储在文本文件中,但如果可能的话,我希望避免使用外部文件.
感谢您提供的任何帮助.
我正在尝试在两台计算机之间建立UDP通信链接.一台计算机正在运行客户端应用程序,另一台正在运行服 客户端应用程序给出错误:
在执行此操作之前,必须调用Bind方法.
以下是我在下面的客户端的代码,我已经评论了错误发生的位置:
public delegate void ShowMessage(string message);
UdpClient udpClient = new UdpClient();
Int32 port = 11000;
public ShowMessage myDelegate;
Thread thread;
private void Form1_Load(object sender, EventArgs e)
{
thread = new Thread(new ThreadStart(ReceiveMessage));
thread.IsBackground = true;
thread.Start();
}
private void ReceiveMessage()
{
while (true)
{
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, port);
//Error on this line
byte[] content = udpClient.Receive(ref remoteIPEndPoint);
if (content.Length > 0)
{
string message = Encoding.ASCII.GetString(content);
this.Invoke(myDelegate, new object[] { message });
}
}
} …
Run Code Online (Sandbox Code Playgroud) 我有一个RadioGroup
我试图缩小,因为它太大了.所以我使用setScaleX()
并setScaleY()
缩小它.
它可以工作,但问题是当我缩放时,视图会改变X和Y的位置.我希望它在缩放后保持相同的左上角坐标.如何在缩放后使View保持不变?
见下面的代码:
CSRadioButton radiobutton = (CSRadioButton) field;
RadioGroup rg = new RadioGroup(this);
rg.setOrientation(RadioGroup.VERTICAL);
JSONArray choices = radiobutton.getChoices();
for(int j = 0; j < choices.length(); j++){
JSONObject currObj = choices.getJSONObject(j);
String text = currObj.getString("text");
RadioButton rb = new RadioButton(this);
rb.setText(text);
rg.addView(rb);
}
rscroll.addView(rg, lp);
rg.setScaleX(0.7f);
rg.setScaleY(0.7f);
Run Code Online (Sandbox Code Playgroud) 我想要做的是使用linq将字符串转换为字符串列表.我尝试以下代码行:
value = "one,two,three,four";
List<string> arr = value.Split(',').Select(s => s.ToList());
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误:
错误1无法将类型'System.Collections.Generic.IEnumerable>'隐式转换为'System.Collections.Generic.List'.存在显式转换(您是否错过了演员?)
如果有人能提供一些令人敬畏的帮助.
我正在使用微调器,并使用所有选项填充下拉菜单。我遇到的问题是,当出现下拉菜单时,它会阻止当前选择的内容。
\n\n这是演示的图片和我的代码:
\n\n\n\n if(field.getType().equalsIgnoreCase("select"))\n {\n CSSelect select = (CSSelect) field;\n\n LinearLayout ll = new LinearLayout(this);\n final Spinner s = new Spinner(this);\n\n TextView t = new TextView(this);\n t.setText("\xe2\x96\xbc");\n t.setTextSize(12);\n t.setBackgroundResource(R.drawable.spinnerbg);\n t.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n s.performClick();\n }\n });\n\n LinearLayout.LayoutParams slp = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT);\n s.setLayoutParams(slp);\n\n ll.addView(s);\n ll.addView(t);\n\n s.setBackgroundResource(R.drawable.spinnerbg);\n\n List<String> list = new ArrayList<String>();\n\n JSONArray choices = select.getChoices();\n\n for(int j = 0; j < choices.length(); j++)\n {\n JSONObject jObj = choices.getJSONObject(j);\n String st = jObj.getString("text");\n list.add(st);\n …
Run Code Online (Sandbox Code Playgroud)