Showing posts with label how. Show all posts
Showing posts with label how. Show all posts

Friday, April 4, 2014

How to detect bad sectors on your hard disk

In another article I explained how to repair bad sectors on HDD and I listed some methods. But how you can detect them?

You can supose that your HDD have bad sectors after some signs like the bigger time to load your OS, data losses, or the impossibility to access your data because the OS didnt load. But its pretty unsure that you have bad sectors.

One method is to use a live cd of any Linux kernel( like Ubuntu, Fedora, LinuxMint etc.) and after you boot from cd and select the try that kernel option, you must go to Accessories and then to Disk Utility.
A HDD with some bad sectors
If you had bad sectors on your HDD, the Disk Utility will show you how many there are ( Ex. You have 3 bad sectors) or if there are many bad sectors, "Disk has a few bad sectors". And after this test you can be sure that your disk is broken and you must try to repair it using one of those methods I posted( link here).

Another method is to use an application like MHDD that you can use after you create an bootable cd/ dvd or usb stick and then test your HDD. Using this program you will see a lot of datas about your HDD.
Read More..

Monday, March 31, 2014

How to create menu in Android using xml file

This code will show how to create menu in android, how to perform action when we click on menu item and how to set icon in menu item.

Just create a new project and give "rl" id to layout or paste below code in layout->main xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".TestMenu"
    android:id="@+id/rl">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

 
Now open menu folder and create test_menu xml file and paste below code


    <item android:id="@+id/red"
        android:title="RED"
        android:icon="@drawable/lion">
       
    </item>
      <item android:id="@+id/blue"
        android:title="BLUE">
       
    </item>
      <item android:id="@+id/green"
        android:title="GREEN">
       
    </item>
      <item android:id="@+id/yellow"
        android:title="YELLOW">
       
    </item>
      <item android:id="@+id/black"
        android:title="BLACK">
      </item>
           <item android:id="@+id/gray"
        android:title="GREY">
        </item>
      
           <item android:id="@+id/pink"
        android:title="PINK">
      </item>
         <item android:id="@+id/white"
        android:title="WHITE">
      </item>
         <item android:id="@+id/close"
        android:title="CLOSE">
      </item>
</menu>

Now open Main java file and paste below code

package test.menutest; //your package name

importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.graphics.Color;
importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.widget.RelativeLayout;

public class TestMenu extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

 //This function will call when we click on menu button
    @Override
    public booleanonCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.test_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
    
//This function will perform action when we click on menu item

    public booleanonOptionsItemSelected(MenuItem item)
    {
      RelativeLayout rl=(RelativeLayout)findViewById(R.id.rl);
      switch(item.getItemId())
      {
      case R.id.red:rl.setBackgroundColor(Color.RED); break;
      case R.id.blue:rl.setBackgroundColor(Color.BLUE); break;
      case R.id.gray:rl.setBackgroundColor(Color.GRAY); break;
      case R.id.yellow:rl.setBackgroundColor(Color.YELLOW); break;
      case R.id.pink:rl.setBackgroundColor(Color.MAGENTA); break;
      case R.id.white:rl.setBackgroundColor(Color.WHITE); break;
      case R.id.green:rl.setBackgroundColor(Color.GREEN); break;
      case R.id.close:finish(); break;
      default:rl.setBackgroundColor(Color.BLACK);
     
      }
     
      return true;
    }  
}

Run code and Enjoy...

Read More..