我一直在这里关注如何制作我自己的Android启动器.我现在可以在列表视图中显示手机上所有已安装的应用程序.如何编辑此代码以使列表按字母顺序排列?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apps_list);
loadApps();
loadListView();
addClickListener();
}
private PackageManager manager;
private List<AppDetail> apps;
private void loadApps(){
manager = getPackageManager();
apps = new ArrayList<AppDetail>();
Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
app.label = ri.loadLabel(manager);
app.name = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(manager);
apps.add(app);
}
}
private ListView list;
private void loadListView(){
list = (ListView)findViewById(R.id.apps_list);
ArrayAdapter<AppDetail> adapter = new ArrayAdapter<AppDetail>(this,
R.layout.list_item,
apps) {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我的字典有这个工作代码:
dict = new Dictionary<string, string>();
using (StreamReader read = new StreamReader("dictionaryfile.csv"))
{
string line;
while ((line = read.ReadLine()) != null)
{
string[] splitword = line.Split(',');
dict.Add(splitword[0], splitword[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
我已在 Windows 窗体中添加了一个按钮,如何分配字典中的随机条目以通过单击按钮显示在消息框中?
如何在按钮上调用setStatusBarColor?我有事件监听器代码,但我不确定如何调用此方法.我正在尝试更改按钮单击时的状态栏颜色.
这是我的代码:
public static void setStatusBarColor(Activity activity, int statusBarColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// If both system bars are black, we can remove these from our layout,
// removing or shrinking the SurfaceFlinger overlay required for our views.
Window window = activity.getWindow();
if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
window.setStatusBarColor(Color.parseColor("#4CAF50"));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的按钮监听器
public void addButtonListener() {
Button = (Button) findViewById(R.id.Button);
Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setStatusBarColor(); …Run Code Online (Sandbox Code Playgroud) C# 我有一个控制台应用程序,可以读取和写入"人员"详细信息的获取/设置列表.它正常工作,直到我尝试将其写入文本文件.有人可以告诉我为什么将"Person"细节的最后一行写入我的文本文件而不是整个列表?
loadData();
Console.WriteLine("All People");
//1st query - just select all people
var queryAllPeople = from person in people select person;
foreach (Person p in queryAllPeople)
{
using (StreamWriter writer = new StreamWriter("people.txt"))
{
writer.WriteLine(p);
}
Console.WriteLine(p);
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud) 有人可以告诉我为什么这不是将值添加到数据库中.表单运行正常,不会返回任何错误.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
connection.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\John\Documents\Setup.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
command.Parameters.AddWithValue("@userName", textBox1.Text);
command.Parameters.AddWithValue("@passWord", textBox2.Text);
command.CommandText = "INSERT INTO Setup (userName, password) VALUES(@userName, @passWord)";
try
{
connection.Open();
int rowsAffected = command.ExecuteNonQuery();
}
catch (Exception ex)
{
// handle exception
}
finally
{
connection.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
仅供参考:我是"新手"我的数据库名为Setup.我手动添加了一个名为myTable的表,其中包含2列userName,另一个名为password,两者都设置为nchar(50)
在线教程之后,制作一个使用Get和Set with class的基本程序.我试图找出如何从文本框中设置值,以便将其存储在我的"存储类"中,清除文本框中的数据,然后再"获取"数据以显示在文本框中,以便证明我的第一次输入数据是否正确设置,如果这是有道理的.
所以我的表单有3个按钮,设置,清除,获取和1个文本框.这是我的"存储类"的代码,
namespace Pracitse{
class Stored
{
private string Colour;
private string getColour(string colour)
{
string displayColour;
displayColour = colour;
return displayColour;
}
public string MyProperty
{
get { return Colour; }
set{ Colour = getColour (value) ;}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的表格中的代码:
private void setBtn_Click(object sender, EventArgs e){
Stored Details = new Stored();
string setcolour;
setcolour = Details.MyProperty;
Details.MyProperty = colourBx.Text;
}
private void getBtn_Click(object sender, EventArgs e)
{
Stored Details = new Stored();
string Displaycolour;
Displaycolour = Details.MyProperty; …Run Code Online (Sandbox Code Playgroud)