手機安全衛士學習(2)

來源:互聯網
上載者:User

標籤:des   android   http   color   io   os   ar   使用   sp   

今天是安全衛士學習第二天,主要涉及以下內容:

1 安全衛士首頁面的布局

  其中涉及gridview的使用,包括布局檔案的引用,以及自訂控制項textview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:gravity="center"
        android:background="#8866ff00"
        android:id="@+id/tv_function_list"
        android:layout_width="fill_parent"
        android:layout_height="55dip"
        android:text="功能列表"
        android:textSize="22sp"
        android:textColor="#000000"/>
    <com.djf.mobilesafty.ui.FocusdTextView
        android:layout_marginTop="10dip"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textSize="22sp"
        android:text="距離季前賽還有11天,欲知詳細資料,請登入查看詳細資料,新賽季更精彩,值得期待··"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <GridView
        android:verticalSpacing="30dip"
        android:layout_marginTop="60dip"
        android:numColumns="3"
        android:id="@+id/gv_item_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

package com.djf.mobilesafty;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class HomeActivity extends Activity {
 private GridView gv_item_home;
 private Myadapter adapter;
 private String[] names  = {
   "手機防盜","通訊衛士","軟體管理",
   "進程管理","流量統計","手機殺毒",
   "緩衝清理","進階工具","設定中心"};
 private static int[] ids = {
  R.drawable.safe,R.drawable.callmsgsafe,R.drawable.app,
  R.drawable.taskmanager,R.drawable.netmanager,R.drawable.trojan,
  R.drawable.sysoptimize,R.drawable.atools,R.drawable.settings
  
 };
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_home);
  gv_item_home = (GridView) findViewById(R.id.gv_item_home);
  adapter = new Myadapter();
  gv_item_home.setAdapter(adapter);
  gv_item_home.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> parent, View view,
     int position, long id) {
    // TODO Auto-generated method stub
    switch (position) {
    case 8:
     Intent intent = new Intent(HomeActivity.this,SetActivity.class);
     
     startActivity(intent);
     break;

    default:
     break;
    }
   }
  });
 }
 public class  Myadapter extends BaseAdapter{

  @Override
  public int getCount() {
   // TODO Auto-generated method stub
   return names.length;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   // TODO Auto-generated method stub
   View view = View.inflate(HomeActivity.this, R.layout.list_item_home, null);
   TextView  tv_item = (TextView) view.findViewById(R.id.tv_item);
   ImageView iv_item = (ImageView) view.findViewById(R.id.iv_item);
   tv_item.setText(names[position]);
   iv_item.setImageResource(ids[position]);
   return view;
  }
  @Override
  public Object getItem(int position) {
   // TODO Auto-generated method stub
   return null;
  }

  @Override
  public long getItemId(int position) {
   // TODO Auto-generated method stub
   return 0;
  }

  
 }

}

2 設定中心的布局,

其中涉及自訂群組件,其中組件中涉及兩個textview,一個checkbox,一個view,以及對自訂群組件的動作處理,資訊的改變

package com.djf.mobilesafty;

import com.djf.mobilesafty.ui.SetItemView;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class SetActivity extends Activity {
 private SetItemView setItemView;
 private SharedPreferences sp;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_set);
  sp = getSharedPreferences("config", MODE_PRIVATE);
  
  setItemView = (SetItemView) findViewById(R.id.siv_update);
  boolean update = sp.getBoolean("update", false);
  if (update) {
   //自動升級已經開啟
   setItemView.SetChecked(true);
   setItemView.SetDesc("開啟升級");
  }
  else {
   //自動升級已經關閉
   setItemView.SetChecked(false);
   setItemView.SetDesc("關閉升級");
  }
  setItemView.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    Editor editor = sp.edit();
    // 組件已經被選中
    if (setItemView.isChecked()) {
     // 設定組件處於非選中狀態,關閉升級
     setItemView.SetChecked(false);
     setItemView.SetDesc("關閉升級");
     editor.putBoolean("update", false);
    } else // 組件沒有被選中
    {
     setItemView.SetChecked(true);
     setItemView.SetDesc("開啟升級");
     editor.putBoolean("update", true);
    }
    editor.commit();
   }
  });
 }
}

自訂群組件布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="55dip"
        android:background="#8866ff00"
        android:gravity="center"
        android:text="設定中心"
        android:textColor="#000000"
        android:textSize="22sp" />

    <com.djf.mobilesafty.ui.SetItemView
        android:id="@+id/siv_update"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </com.djf.mobilesafty.ui.SetItemView>

</LinearLayout>

手機安全衛士學習(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.